Today,
My post is about how to display Related Notes of an Entity in CRM Subgrid with Sorting, Refresh, Delete Multiple and Open Multiple Records:
For Example we want to display all Notes of Account Entity :
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
My post is about how to display Related Notes of an Entity in CRM Subgrid with Sorting, Refresh, Delete Multiple and Open Multiple Records:
For Example we want to display all Notes of Account Entity :
- First of all Add IFrame to Account Entity with the following Properties:
2. Then Add New JavaScript library to the form Properties and Paste the following code in it.
function Notes() {
- if (Xrm.Page.ui.getFormType() == 1) {
- return;
- }
- var NotesGrid = document.getElementById("IFRAME_RelatedAttachments");
- if (NotesGrid == null || NotesGrid.readyState != "complete") {
- setTimeout("Notes()", 2000);
- return
- }
- NotesGrid.src = "about:blank";
- var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true' count='6'><entity name='annotation'><attribute name='annotationid'/><attribute name='subject'/><attribute name='notetext'/><attribute name='modifiedby'/><attribute name='filename'/><attribute name='isdocument'/><attribute name='filesize'/><attribute name='modifiedon'/><order attribute='modifiedon' descending='false'/><link-entity name='" + Xrm.Page.data.entity.getEntityName() + "' from='" + Xrm.Page.data.entity.getEntityName() + "id" + "' to='objectid' alias='aa'><filter type='and'><condition attribute='" + Xrm.Page.data.entity.getEntityName() + "id" + "' operator='eq' value='" + Xrm.Page.data.entity.getId() + "'/></filter></link-entity></entity></fetch>";
- var layoutXml = "<grid name='resultset' object='5' jump='subject' select='1' icon='1' preview='1'><row name='result' id='annotationid'><cell name='isdocument' width='40' /><cell name='subject' width='200' /><cell name='filename' width='200' /><cell name='notetext' width='200' /><cell name='filesize' width='100' /><cell name='modifiedby' width='150' /><cell name='modifiedon' width='100' /></row></grid>";
- EmbedAdvancedFindView("IFRAME_RelatedAttachments", "annotation", fetchXml, layoutXml, "name", "false", "{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}");
- // to remove the toolbar items from the advance find grid
- var iFrame1 = null;
- iFrame1 = crmForm.all.IFRAME_RelatedAttachments;
- var iDoc1 = iFrame1.contentWindow.document;
- iFrame1.attachEvent("onreadystatechange", Ready1);
- RemoveWhiteSpace();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function EmbedAdvancedFindView(iFrameId, entityName, fetchXml, layoutXml, sortCol, sortDescend, defaultAdvFindViewId) {
try {
var iFrame = document.getElementById(iFrameId);
var httpObj = new ActiveXObject("Msxml2.XMLHTTP");
var url = "/" + ORG_UNIQUE_NAME + "/advancedFind/fetchData.aspx";
var params = "FetchXML=" + fetchXml
+ "&LayoutXML=" + layoutXml
+ "&EntityName=" + entityName
+ "&DefaultAdvFindViewId=" + defaultAdvFindViewId
+ "&ViewType=1039";
httpObj.Open("POST", url, true);
httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpObj.setRequestHeader("Content-length", params.length);
httpObj.onreadystatechange = function () {
if (httpObj.readyState == 4 && httpObj.status == 200) {
var doc = iFrame.contentWindow.document;
iFrame.src = null;
doc.open();
doc.write(httpObj.responseText);
doc.close();
// doc.body.style.padding = "0px";
// doc.body.style.backgroundColor = "#eaf3ff";
}
}
httpObj.send(params);
}
catch (e) {
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Ready1() {
try {
var iFrame = crmForm.all.IFRAME_RelatedAttachments;
var iDoc1 = iFrame.contentWindow.document;
if (iDoc1.getElementById("gridMenuBar") != null)
iDoc1.getElementById("gridMenuBar").style.display = "none";
} catch (e) {
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3. Call the Notes() function on Onload event of Account Form, and you will see a Subgrid Displayed with Sorting on each column, and Refresh Button.