Feedjit

Articles for you

Thursday, May 29, 2014

CRM 2011 like Subgrid With Sorting in JavaScript, CRM 2011 Display fetchxml in IFrame, Display Custom Advance Find view in Iframe 2014,

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 :

  1. 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() {
  1.     if (Xrm.Page.ui.getFormType() == 1) {
  2.         return;
  3.     }
  4.     var NotesGrid = document.getElementById("IFRAME_RelatedAttachments");
  5.     if (NotesGrid == null || NotesGrid.readyState != "complete") {

  6.         setTimeout("Notes()", 2000);
  7.         return

  8.     }
  9.     NotesGrid.src = "about:blank";
  10.     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>";



  11.     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>";


  12.     EmbedAdvancedFindView("IFRAME_RelatedAttachments", "annotation", fetchXml, layoutXml, "name", "false", "{DDDFF6AE-2F52-4640-B2BB-2BA59DA0777C}");

  13.     // to remove the toolbar items from the advance find grid
  14.     var iFrame1 = null;
  15.     iFrame1 = crmForm.all.IFRAME_RelatedAttachments;
  16.     var iDoc1 = iFrame1.contentWindow.document;
  17.     iFrame1.attachEvent("onreadystatechange", Ready1);
  18.     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.


Read More

Articles for you