自定义电子邮件的 regardingobjectid 查找下拉列表

Customize Email's regardingobjectid lookup dropdown

我尝试使用以下代码自定义电子邮件的 regardingobjectid 查找下拉列表:

var regardingobjectid = Xrm.Page.getControl("regardingobjectid");
/* The value of viewId is a dummy value, 
   and only needs to be unique among the other available views for the lookup. */
var viewId = '{00000000-0000-0000-0000-000000000001}';
var entityName = 'lu_service';
var viewDisplayName = 'service - custom view';
var fetchXml =
'<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >' +
  '<entity name="lu_service">' +
     '<attribute name="lu_serviceid" />' +
     '<attribute name="lu_name" />' +
     '<attribute name="createdon" />' +
     '<order attribute="lu_name" descending="false" />' +
   '</entity>' +
'</fetch>';

var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
lookupService.SetParameter("entityName", "lu_service");
var result = lookupService.Execute();
var objectTypeCode = result.ReturnValue;
var layoutXml =
'<grid name="resultset" object="' + objectTypeCode + '" jump="lu_name" select="1" icon="1" preview="1">' +
   '<row name="lu_service" id="lu_serviceid">' +
      '<cell name="lu_name" width="300" />' +
      '<cell name="createdon" width="125" />' +
   '</row>' +
'</grid>';
regardingobjectid.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

我认为这段代码应该做两件事:

1.自定义查找下拉列表,即在点击查找时显示的下拉列表中显示所需类型的记录(在我的示例中:lu_service)场.

2. 添加自定义视图到 window 点击 "Look Up More Records" link 时打开的 link (在查找的末尾列出下拉菜单)。

结果是1不行,2行

我的问题是:1 应该有效吗?如果没有,是否可以实现?

对于 2015 版本中的第 1 点,您必须使用 addPreSearch and addCustomFilter to filter out the unwanted entities in the dropdown list. This is the only supported way/workaround. Read more

例如,下面的过滤器将显示 lu_service 并从 regardingobjectid 查找中删除任何 account。技巧是account不会有nullaccountid.

var serviceFilter = "<filter type='and'><condition attribute='lu_serviceid' operator='not-null' /></filter>";
//remove accounts
var accountFilter = "<filter type='and'><condition attribute='accountid' operator='null' /></filter>";
Xrm.Page.getControl('regardingobjectid').addCustomFilter(serviceFilter, "lu_service");
Xrm.Page.getControl('regardingobjectid').addCustomFilter(accountFilter, "account");