Pages

Thursday, 20 June 2013

Bind data to subgrid dynamically in CRM 2011

The following javascript web resource is used for bind data which is account related activities to subgrid with help of account number.

This is a special functionality in crm 2011.

When we entering a account number, automatically bind that account related activities using onkeyup(it is an event for textbox).


function SetSubGridInfo(accnum) {
    var ProjectGrid = document.getElementById("Activities_Subgrid");
    if (ProjectGrid == null || ProjectGrid.readyState != "complete") {
        setTimeout(SetSubGridInfo, 500);
        return;
    }
    var fetchxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchxml += "<entity name='activitypointer'>";
    fetchxml += "<attribute name='subject' />";
    fetchxml += "<attribute name='ownerid' />";
    fetchxml += "<attribute name='prioritycode' />";
    fetchxml += "<attribute name='regardingobjectid' />";
    fetchxml += "<attribute name='activitytypecode' />";
    fetchxml += "<attribute name='statecode' />";
    fetchxml += "<attribute name='scheduledstart' />";
    fetchxml += "<attribute name='scheduledend' />";
    fetchxml += "<attribute name='activityid' />";
    fetchxml += "<attribute name='instancetypecode' />";
    fetchxml += "<order attribute='scheduledend' descending='false' />";
    fetchxml += "<filter type='and'>";
    fetchxml += "<condition attribute='isregularactivity' operator='eq' value='1' />";
    fetchxml += "</filter>";
    fetchxml += "<link-entity name='systemuser' from='systemuserid' to='owninguser' visible='false' link-type='outer' alias='activitypointerowningusersystemusersystemuserid'>";
    fetchxml += "<attribute name='internalemailaddress' />";
    fetchxml += "</link-entity>";
    fetchxml += "<link-entity name='account' from='accountid' to='regardingobjectid' alias='aa'>";
    fetchxml += "<filter type='and'>";
    fetchxml += "<condition attribute='accountnumber' operator='eq' value='" + anum + "' />";
    fetchxml += "</filter>";
    fetchxml += "</link-entity>";
    fetchxml += "</entity>";
    fetchxml += "</fetch>";
    ProjectGrid.control.setParameter("fetchxml", fetchxml);
    ProjectGrid.control.refresh();
}
function registerOnKeyUp() {
    var attr = "new_accountnumber";
    var el = document.getElementById(attr);
    el.onkeyup = function () {
        var edValue = document.getElementById(attr);
        var s = edValue.value;
        SetSubGridInfo(s);
    }
}

2 comments:

  1. Hi Suresh Kumar,

    Nice Article, thanks for sharing this information. Looking forward for more posts like this.







    Dynamics CRM Developers

    ReplyDelete
  2. is there any way to dynamically change the entity name in the fetchxml? i try and it says that the subgrid entity doesnt match.

    ReplyDelete