// Use this approach if your parent and child list are connected with a common text string, // for example when using cascading dropdown or vLookupID / vLookupParentID // // Base function – do not edit function getRelatedItemsText(arg) { var isGuid = arg.listName.charAt(0) === "{", b = [], vf = ["ID", "FileDirRef"], res; jQuery.each(arg.select, function (i, fin) { vf.push(fin); }); res = spjs.utility.queryItems({ "listName": arg.listName, "query": arg.filter, "viewFields": vf, "rowLimit": arg.itemLimit }); if (res.count > 0) { // Header row b.push("<tr class='dffs_relatedItems_headerRow'>"); if (arg.linkToItem.view.on) { b.push("<td class='dffs_relatedItems_headerCell'></td>"); } if (arg.linkToItem.edit.on) { b.push("<td class='dffs_relatedItems_headerCell'></td>"); } jQuery.each(arg.viewFields, function (i, o) { b.push("<td class='dffs_relatedItems_headerCell'>" + o.label + "</td>"); }); b.push("</tr>"); jQuery.each(res.items, function (i, item) { var viewLink = "/" + item.FileDirRef.split(";#")[1] + "/DispForm.aspx?ID=" + item.ID, editLink = "/" + item.FileDirRef.split(";#")[1] + "/EditForm.aspx?ID=" + item.ID; b.push("<tr class='dffs_relatedItems_row'>"); if (arg.linkToItem.view.on) { b.push("<td class='dffs_relatedItems_cell'><img style='cursor:pointer;vertical-align:middel;' onclick='openInDlg(\"" + viewLink + "\")' src='" + arg.linkToItem.view.icon + "'></a></td>"); } if (arg.linkToItem.edit.on) { b.push("<td class='dffs_relatedItems_cell'><img style='cursor:pointer;vertical-align:middel;' onclick='openInDlg(\"" + editLink + "\")' src='" + arg.linkToItem.edit.icon + "'></a></td>"); } jQuery.each(arg.viewFields, function (j, o) { var a = o.fin.split("/"), val; if (a.length === 1) { val = item[a[0]]; } else { val = item[a[0]][a[1]]; } if (o.parseFunction !== null) { val = window[o.parseFunction](val, item); } b.push("<td class='dffs_relatedItems_cell'>" + val + "</td>"); }); b.push("</tr>"); }); } if (b.length === 0) { b.push("<div style='padding:10px;'>" + arg.labels.noItemsFound + "</div>"); } else { b.unshift("<table class='dffs_relatedItems_table'>"); b.push("</table>"); } jQuery("#" + arg.placeholderID).html(b.join("")); } // Open form in dialog function openInDlg(url){ var options = { "url":url }; SP.UI.ModalDialog.showModalDialog(options); } // Parse function for people picker function getPeoplePickerName(v, item) { var r = ""; if (v !== null) { r = v.split(";#")[1]; } return r; } // Parse function for date fields function dateObjToFriendlyDate(v, item) { var r = ""; try { var d = new Date(v); r = d.toLocaleDateString(_spPageContextInfo.currentUICultureName); } catch (ignore) { // Nothing } return r; } // Function call - change parameters here function dffs_ready(){ getRelatedItemsText({ "placeholderID":"ReverseLookup", "listName":"{1ACC9539-803D-41AF-8870-C59454BB0DA1}", // Use DisplayName or GUID (GUID must start and end with curly brace) "listBaseUrl":_spPageContextInfo.webServerRelativeUrl, "filter": ""+getFieldValue("Title")+";", "select":["Title","Author","Author","Created"], "expand":["Author"], "linkToItem":{ "view":{ "on":true, "icon":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABMUlEQVQ4T6WSvUsDQRDF522bYKmgtaS2kKvD3P4PoiD4WQmSKpDCUtBOOxVNJQjWVnuTA7urrIOtCNopB3YzEkkgJpeQj2kWhsePt28eqDve+2VVrQPYIKJFIvo0swfn3FkI4b2nG3zRWTCzB3BlZhd5njezLPuOomihVCptAqgR0ZGIhCIIqtVqxTl3D+AgSZKXQVEcx2tmdqOqW2matoccMPM5EbVF5HaUTWbeI6KKiNSJyPp1YOZH51wjhPA6CuC9X1XVUwD7SZJ8/QPEcfxkZrsi8jHGwRKAuyLd/A66GbyJyOVMGcx9hXE9KJfLOwAaZvZjZtutVuu5sEid5bgmquoKgGtVPR6E/DVxkmHmdSJqElGtv5UTA7pfHYJMBSiCTA3oQTqZmNnhTIA+Jye/ts29i6m1dSsAAAAASUVORK5CYII=" }, "edit":{ "on":true, "icon":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA6klEQVQ4T+WTPQoCMRBG5yNrs9VWijewzwWEqa30BN5ABGsbUbAQBFvP4AUWFvcSgqWVIFYWCkNGIruw+LOrtSmSEPLeTMIMKBvM3ACwVtW+P6rax3F8fNzzUwYnRNTKhRXrTlXbXlIUPKLn5k+CYqb/KrDW1sIwjNI0PRGR/vyJ1towiqI5EfUBTH4SZPACwE1ElkEQrL4WFGFjzFhEpkR0+UrwDs6yGFUKyuAkSa6lgir4uRdeSpmZewA6xpiBf3Oeto+cl3ppBsw8A1BX1SaAvYiMinBZNx5UtUtEQwBn59zGObd9hr3gDipMDAs8Vm/dAAAAAElFTkSuQmCC" } }, "viewFields":[ { "label":"Title", "fin":"Title", "parseFunction":null }, { "label":"Author", "fin":"Author", "parseFunction":"getPeoplePickerName" }, { "label":"Created", "fin":"Created", "parseFunction":"dateObjToFriendlyDate" } ], "labels":{ "noItemsFound":"There are no related items" }, "itemLimit":3 }); }