JS操作lookup control
以contact的parentcustomerid为例,它是一个lookup field。lookup type为account和contact。默认type为account
如果要设置默认type为contact的话,可以document.getElementById("parentcustomerid").setAttribute("defaulttype", "2"); // 2 是contact object type code
如果lookup type为account和contact,可以document.getElementById("parentcustomerid").setAttribute("lookuptypes", "1, 2");
设置default view可以Xrm.Page.getControl("parentcustomerid").setDefaultView("E88CA999-0B16-4AE9-B6A9-9EDC840D42D8");
如果想禁止用户选择其他的view,可以document.getElementById("parentcustomerid").setAttribute("disableViewPicker", "1");
为lookup字段添加一个自定义视图 (addCustomView)
var viewId = "{C7034F4F-6F92-4DD7-BD9D-9B9C1E996380}";
var viewDisplayName = "SDK Sample View";
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='systemuser'>
<attribute name='systemuserid' />
<attribute name='fullname' />
<attribute name='businessunitid' />
<order attribute='fullname' descending='false' />
<link-entity name='businessunit' from='businessunitid' to='businessunitid' visible='false' link-type='outer' alias='a_89c4efa5341e42d5ac34e759aa182065'>
<attribute name='name' />
</link-entity>
</entity>
</fetch>";
Xrm.Page.getControl("parentaccountid").addCustomView(viewId, "account", viewDisplayName, fetchXml, layoutXml, true);