如何使用 JavaScript 将自定义 FetchXML 应用到子网格

问题描述 投票:0回答:5

将自定义 FetchXML 应用到子网格的实现似乎已从 CRM 2011/13 更改为 Dynamics 365。该更改与

GridControl.SetParameter()
有关。

我关注了许多讨论同一问题的文章,但目前 Dynamics 365 Online 上没有任何效果。 有没有其他方法可以实现相同的功能?

在下面的代码中,我尝试获取与帐户相关的所有电话和电子邮件活动,并将它们显示在帐户表单上的子网格上。

//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
dynamics-crm crm microsoft-dynamics dynamics-crm-online dynamics-crm-365
5个回答
0
投票

使用Xrm页面对象,我们可以将JavaScript绑定到子网格的onload事件。

可以使用 Ribbon Workbench 工具将 JavaScript 绑定到子网格。

有关如何在子网格事件上编写 JavaScript 的示例代码,请参阅此链接 http://www.inogic.com/blog/2015/11/identify-the-trigger-for-an-on-load-event-for-sub-grid-in-dynamics-crm/


0
投票

社区帖子建议不要采用这种不受支持的方法。建议使用

RetrieveMultiple
预操作插件来拦截调用并传递我们自定义的 fetchxml 查询来获得结果。

这也有其自身的缺点,因为昂贵的事件前调用会降低性能并且必须限制确切的检索调用。但这至少在受支持的区域内。


0
投票

加载表单上的脚本:

var control = Xrm.Page.getControl("Your Subgrid control");
var grid = control.getGrid();
var fetchXml = "<fetch version='1.0' output-format='xml-platform' 
mapping='logical' distinct='false'>...</fetch>" //Your fetch Xml
grid.setParameter("fetchXML", fetchXml);    

0
投票

还有一种选择。您可以尝试使用 FetchToSubGrid PCF 控件。它将多行文本字段(带有 fetchXml 字符串值)转换为子网格。

https://marketplace.bevercrm.com/pcf-controls/7


0
投票
var fetchXml = `<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                  <entity name="lead">
                    <attribute name="pg_leadid" />
                    <attribute name="fullname" />
                    <attribute name="emailaddress1" />
                    <attribute name="mobilephone" />
                    <attribute name="leadsourcecode" />
                    <filter>
                        <filter type="or">
                          <condition attribute="emailaddress1" operator="eq" value="`+ email +`" />
                          <condition attribute="mobilephone" operator="eq" value="`+ phone +`" />
                        </filter>
                        <filter>
                          <condition attribute="pg_leadid" operator="ne" value="`+ leadId +`" />
                        </filter>
                    </filter>
                  </entity>
                </fetch>`;

var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("DuplicateLeads_SubGrid");
if (gridContext == null || gridContext == undefined) {
    return;
}

gridContext.setFilterXml(fetchXml);
gridContext.refresh();
© www.soinside.com 2019 - 2024. All rights reserved.