Javascript D365自定义JS Web资源-引用错误:Web资源方法不存在:preFilterLookup

Javascript D365自定义JS Web资源-引用错误:Web资源方法不存在:preFilterLookup,javascript,web,dynamics-crm,crm,dynamics-crm-2013,Javascript,Web,Dynamics Crm,Crm,Dynamics Crm 2013,我们试图上传一个小的JS web资源来过滤特定的查找字段,但我一直收到一个错误:ReferenceError:web资源方法不存在:preFilterLookup 下面是我们尝试使用的代码: function preFilterLookup() { Xrm.Page.getControl("new_opportunitytypelookup").addPreSearch(function () { addLookupFilter(); }); } f

我们试图上传一个小的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);
    }
}
函数预过滤器查找(){
Xrm.Page.getControl(“新的机会类型查找”).addPreSearch(函数(){
addLookupFilter();
});
}
函数addLookupFilter(){
var oppScope=Xrm.Page.getAttribute(“new_opportunityscope”).getText();
if(oppScope.getText()=“BMS运营外包”){
fetchXml=”
{42403355-925B-EB11-A812-000D3A8C6500}
{DF7CC32A-925B-EB11-A812-000D3A8C6500}
";
Xrm.Page.getControl(“new_opportunitytypelookup”).addCustomFilter(fetchXml);
}
}

我最初认为,我们甚至可以使用定义的方法为特定字段设置正确的“On Change”事件。首先,您应该在表单加载事件上有一个方法,并为其中的查找定义addPreSearch()。
另外,Dynamics 365中不推荐使用Xrm.Page,因此您应该改用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);
    }
}
函数addLookupFilter(executionContext){
var formContext=executionContext.getFormContext();
var oppScope=formContext.getAttribute(“new_opportunityscope”).getText();
if(oppScope==“BMS运营外包”){
var fetchXml=”
{42403355-925B-EB11-A812-000D3A8C6500}
{DF7CC32A-925B-EB11-A812-000D3A8C6500}
";
formContext.getControl(“新的机会类型查找”).addCustomFilter(fetchXml);
}
}

另外,在注册onLoad事件时,不要忘记传递执行上下文。

那么函数
prefilterflookup
是如何连接到表单的呢?
fetchXml=
语句不正确。这实际上是您试图运行的代码吗?我将看一看fetchXML-谢谢!太好了,非常感谢你。我将尝试一下,并会让你知道它是如何工作的!