我们尝试上传一个小的JS资源来筛选特定的查找字段,但是我一直收到一个错误:ReferenceError: web不存在: preFilterLookup
下面是我们试图使用的代码:
function preFilterLookup() {
Xrm.Page.getControl("new_opportunitytypelookup").addPreSearch(function () {
addLookupFilter();
});
}
function addLookupFilter() {
var oppScope = Xrm.Page.getAttribute("new_opportunityscope").getText();
if (oppScope.getText()=="BMS Operational Outsourcing") {
fetchXml = "<filter type="and">
<condition attribute="cr2f5_opportunitytypeid" operator="in">
<value uiname="aaS Offering" uitype="cr2f5_opportunitytype">{42403355-925B-EB11-A812-000D3A8C6500}</value>
<value uiname="Operational Outsourcing" uitype="cr2f5_opportunitytype">{DF7CC32A-925B-EB11-A812-000D3A8C6500}</value>
</condition>
</filter>";
Xrm.Page.getControl("new_opportunitytypelookup").addCustomFilter(fetchXml);
}
}我最初认为我们甚至使用定义了机会范围-关于变更事件的方法,为我们的特定字段设置了正确的"On“事件设置。
发布于 2021-03-16 05:53:19
首先,您应该在form事件上有一个方法,并为其中的查找定义addPreSearch()。
此外,Xrm.Page在Dynamic365号中被废弃,因此您应该使用formContext。
因此,我们得到了这个方法,它应该在加载表单时触发:
function onLoad(executionContext){
var formContext = executionContext.getFormContext();
formContext.getControl("new_opportunitytypelookup").addPreSearch(function () {
addLookupFilter(executionContext);
});
}剩下的代码是:
function addLookupFilter(executionContext) {
var formContext = executionContext.getFormContext();
var oppScope = formContext.getAttribute("new_opportunityscope").getText();
if (oppScope == "BMS Operational Outsourcing") {
var fetchXml = "
<filter type="and">
<condition attribute="cr2f5_opportunitytypeid" operator="in">
<value uiname="aaS Offering" uitype="cr2f5_opportunitytype">{42403355-925B-EB11-A812-000D3A8C6500}</value>
<value uiname="Operational Outsourcing" uitype="cr2f5_opportunitytype">{DF7CC32A-925B-EB11-A812-000D3A8C6500}</value>
</condition>
</filter>";
formContext.getControl("new_opportunitytypelookup").addCustomFilter(fetchXml);
}
}此外,在注册onLoad事件时,不要忘记传递执行上下文。
https://stackoverflow.com/questions/66642506
复制相似问题