首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >D365自定义JS资源- ReferenceError: Web资源方法不存在: preFilterLookup

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

Stack Overflow用户
提问于 2021-03-15 17:10:39
回答 1查看 1.3K关注 0票数 1

我们尝试上传一个小的JS资源来筛选特定的查找字段,但是我一直收到一个错误:ReferenceError: web不存在: preFilterLookup

下面是我们试图使用的代码:

代码语言:javascript
复制
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“事件设置。

EN

回答 1

Stack Overflow用户

发布于 2021-03-16 05:53:19

首先,您应该在form事件上有一个方法,并为其中的查找定义addPreSearch()。

此外,Xrm.Page在Dynamic365号中被废弃,因此您应该使用formContext

因此,我们得到了这个方法,它应该在加载表单时触发:

代码语言:javascript
复制
function onLoad(executionContext){
   var formContext = executionContext.getFormContext();
   formContext.getControl("new_opportunitytypelookup").addPreSearch(function () {
      addLookupFilter(executionContext);
   });
}

剩下的代码是:

代码语言:javascript
复制
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事件时,不要忘记传递执行上下文。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66642506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档