D365自定义JS Web资源-ReferenceError:Web资源方法不存在:preFilterLookup



我们试图上传一个小型JS web资源来过滤特定的查找字段,但我一直收到一个错误: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);
}
}

我最初认为我们甚至有正确的";关于变化";使用方法定义的Opportunity Scope-On Change event 为我们的特定字段设置事件

首先,您应该在表单加载事件上有一个方法,并为其中的查找定义addPreSearch((。
还有Xrm。页面在Dynamics365中已弃用,因此应改用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事件时,不要忘记传递执行上下文。

最新更新