How to apply custom FetchXML to a Subgrid using JavaScript

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 20:48:48

问题


The implementation of applying custom FetchXML to a Subgrid appears to have changed from CRM 2011/13 to Dynamics 365. The change is with respect to GridControl.SetParameter().

I have followed many articles talking about this same issue but nothing is working at the moment on Dynamics 365 Online. Is there any alternative method to achieve the same functionality?

In my below code, I am trying to fetch all of the phone call and email activities related to the account and show them on the Subgrid which is on the account form.

//Shows only the PhoneCall activities related to Organisation
//var allPhoneCallsGrid = window.parent.document.getElementById("AllPhoneCalls"); //Not supported by Microsoft
//var allPhoneCallsGrid = document.getElementById("AllPhoneCalls"); //Not Supported by Microsoft

var allPhoneCallsGrid = Xrm.Page.getControl("AllPhoneCallactivities"); //Sub-grid is on the Account Form

if (allPhoneCallsGrid == null) {
  setTimeout(function() {
    AccountForm.AccountFormOnLoad();
  }, 2000); //if the grid hasn’t loaded run this again when it has
  return;
}

var accountId = Xrm.Page.data.entity.getId();
var allPhoneCallsfetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
  "  <entity name='activitypointer'>" +
  " <attribute name='activitytypecode' />" +
  "        <attribute name='subject' />" +
  "        <attribute name='ownerid' />" +
  "        <attribute name='prioritycode' />" +
  "        <attribute name='regardingobjectid' />" +
  "        <attribute name='activityid' />" +
  "        <attribute name='scheduledstart' />" +
  "        <attribute name='scheduledend' />" +
  "        <attribute name='statecode' />            " +
  "        <attribute name='community' />   " +
  "    <order attribute='modifiedon' descending='false' />" +
  "    <filter type='and'>" +
  "      <condition attribute='activitytypecode' operator='ne' value='4206' />" +
  "      <condition attribute='activitytypecode' operator='eq' value='4210' />" +
  "    </filter>" +
  "    <link-entity name='incident' from='incidentid' to='regardingobjectid' alias='ad'>" +
  "      <filter type='and'>" +
  "        <condition attribute='account' operator='eq' uitype='account' value='" + accountId + "' />" +
  "      </filter>" +
  "    </link-entity>" +
  "  </entity>" +
  "</fetch>";

allPhoneCallsGrid.control.SetParameter("fetchXml", allPhoneCallsfetchXml); //Unable to get property 'SetParameter' of undefined or null reference
//allPhoneCallsGrid.getGrid().setParameter("fetchXml", allPhoneCallsfetchXml);
allPhoneCallsGrid.control.Refresh(); //refresh the sub grid using the new fetch xml

回答1:


Using Xrm page object, we can bind JavaScript to the onload event of the subgrid.

JavaScript can be bind to the subgrid using Ribbon Workbench tool.

For sample code, on how to write JavaScript on subgrid event, please refer this link http://www.inogic.com/blog/2015/11/identify-the-trigger-for-an-on-load-event-for-sub-grid-in-dynamics-crm/




回答2:


Community thread advised against this unsupported approach. Recommendation is to use RetrieveMultiple pre-operation plugin to intercept the call & pass our custom fetchxml query to achieve the result.

This is also having its own disadvantage, because of performance degradation by costly pre-event call & have to limit the exact retrieval call. But this is atleast in supported area.



来源:https://stackoverflow.com/questions/44024756/how-to-apply-custom-fetchxml-to-a-subgrid-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!