Dynamics CRM - 通过 JavaScript 使用 Fetch XML 对 Sub-grid 结果进行筛选过滤

与世无争的帅哥 提交于 2019-12-21 11:02:27

一、如何指定 Partylist 类型字段能 lookup 的实体(以 Appointment 中某个字段为例子):

      代码如下:

var control = Xrm.Page.getControl("requiredattendees");
control.getAttribute().setLookupTypes(["systemuser", "contact"]);

 

      执行前:

 

 

      执行后:

 

 

二、使用 JavaScript 对 sub-grid 进行过滤,具体过程如下:

      1.首先打开 CRM 系统的 Advanced Find:

 

      2.选择 Sub grid 对应的 Entity(以 Appointment 为例子),并添加所需要的筛选条件,点击下载 Fetch XML:

 

      3.下载后得到的文本内容如下(有所省略,只是一个sample):

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="appointment">
    <attribute name="..." />
    <attribute name="..." />
    ...
    <attribute name="..." />
    <order attribute="..." descending="true" />
    <filter type="and">
      <condition attribute="actualend" operator="on-or-after" value="2019-04-16" />
    </filter>
  </entity>
</fetch>

 

      4.在 JavaScript 中调用 XML 对 Sub grid 进行过滤:

var sSubGridName = "..." //Sub grid的名字
var caseXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + 
"<entity name='appointment'>" + 
"<attribute name='...' />" + 
"..." + 
"<attribute name='...' />" +
"<order attribute='...' descending='true' />" + 
"<filter type='and'>" +
"<condition attribute='actualend' operator='on-or-after' value='2019-04-16' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var SubGridDetails = window.parent.document.getElementById(sSubGridName);
if (SubGridDetails != null) {
    if (SubGridDetails.control != null) {
        SubGridDetails.control.SetParameter("fetchXml", caseXml); //set the fetch xml to the sub grid   
        SubGridDetails.control.refresh(); //refresh the sub grid using the new fetch xml
    }
}

 

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