Dynamics CRM 日常使用JS整理(三)

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

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

执行前:

 

执行后:

 

二、判断当前窗口是否为新建的 Record:

if (Xrm.Page.ui.getFormType() == 1){
    //1:Create
}
else{
    //0:
    //2:Update
    //3:Read Only
    //4:Disabled
    //6:Bulk Edit
}

可参考官方DOC:https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg327828(v=crm.8)

三、为 Sub grid 添加 filter,具体过程如下:

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
    }
}

猜你喜欢

转载自www.cnblogs.com/Sunny20181123/p/10718044.html