Dynamics CRM - 經過 JavaScript 使用 Fetch XML 對 Sub-grid 結果進行篩選過濾

1、如何指定 Partylist 類型字段能 lookup 的實體(以 Appointment 中某個字段爲例子):

      代碼以下:app

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

 

      執行前:fetch

 

 

      執行後:ui

 

 

2、使用 JavaScript 對 sub-grid 進行過濾,具體過程以下:

      1.首先打開 CRM 系統的 Advanced Find:spa

 

      2.選擇 Sub grid 對應的 Entity(以 Appointment 爲例子),並添加所須要的篩選條件,點擊下載 Fetch XML:code

 

      3.下載後獲得的文本內容以下(有所省略,只是一個sample):orm

<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 進行過濾:xml

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
 } }
相關文章
相關標籤/搜索