【问题标题】:"Function Expected" error in JsProvider.ashx after setting a lookup field设置查找字段后 JsProvider.ashx 中出现“预期功能”错误
【发布时间】:2017-05-11 16:23:09
【问题描述】:

我有一个 HTML 页面,当单击自定义实体页面的功能区按钮时会打开该页面。在这个页面中运行的 JS 代码是做一些业务逻辑的,最终需要在自定义实体页面上更新一个查找字段。

目前,为了设置查找值,我正在执行以下操作*:

window.opener.Xrm.Page.getAttribute("ik_reportid").setValue([{
    id: "d67aa9d8-c528-e711-80f2-005056b74923",
    name: "test record",
    entityType: "ik_report"
}]);

*注意:以上内容是为简化此问题而编写的硬编码。我向你保证,问题不在于这些值,而在于其他地方。

这样做后,HTML 页面继续使用其现有代码,并最终调用window.opener.Page.data.refresh(true),然后使用window.close() 关闭自身。

问题是当打开器页面刷新时,我得到一个错误“预期功能”,打开调试器让我看到JsProvider.ashx中的以下行:

Mscrm.FormInputControl.LookupUIBehavior.$2I=function($p0,$p1){if(!parseInt($p0.type)&&!parseInt($p1.type)||parseInt($p0.category)===LookupItemCategories.UNKNOWN_EMAIL&&parseInt($p1.category)===LookupItemCategories.UNKNOWN_EMAIL)

我查看了p0 和p1 的值,发现它们没有category 属性。但是,当我在页面本身时尝试使用相同的代码设置相同查找字段的值时(即省略window.opener', and even calling arefresh`),我没有收到任何错误。

此外,我注释掉了 HTML 页面代码中的 refresh 调用。这也没有帮助:当我单击实体页面上的保存按钮时,我再次收到“预期功能”错误,现在在 Global.ashx(b 显然应该是一个功能):

Sys._isInstanceOfType=function(c,b){if(typeof b==="undefined"||b===null)return false; if(b instanceof c) return true;

不知道是什么原因造成的。欢迎任何帮助。

【问题讨论】:

  • 0 如果对话框没有打开,你能确认错误不会发生吗? 1 如果在对话框中注释掉所有的总线逻辑,是否会出现错误? 2 如果在对话框仍处于打开状态时单击“保存”会出现这种情况吗? 2 你是如何打开对话框的? 3 不要通过 window.opener 从对话框中触发 setValue 和刷新,而是尝试向您的功能区 JS 添加代表对话框执行这些操作的函数。所以你的对话会调用window.opener.setReportId([{/*snip*/}]),然后是window.opener.refreshForm()。
  • 0 - 是,1 -“总线逻辑”? 2a - 是的,2b - window.open 3 - 我会试试的
  • @Polshgiant,它成功了,谢谢!

标签: javascript dynamics-crm dynamics-crm-2015


【解决方案1】:

在窗口之间发布消息应该满足您的要求。您可以找到更多信息here 基本上在你的父窗口中做这样的事情:

window.onmessage = function (e) {
     //e.data will contain some payload
    Xrm.Page.getAttributes("xxx").setValue(e.data);
};

或兼容所有浏览器:

if (window.addEventListener) {
  window.addEventListener('message', function (e) {
    //e.data will contain some payload
    Xrm.Page.getAttributes("xxx").setValue(e.data);
  });
}
else { // IE8 or earlier
  window.attachEvent('onmessage', function (e) {
     //e.data will contain some payload
     Xrm.Page.getAttributes("xxx").setValue(e.data);
  });
}

现在在您的子窗口中只使用 postMessage 发送结果

window.opener.postMessage("I'm the result", '*');

我通常以这种方式处理您描述的场景。另一种解决方案是在父窗口上创建回调

window.callback = function() {
   //do your stuff here
}

并从子窗口调用此回调:

childWindow.opener.callback();

但我个人更喜欢 postMessage 方法,有时我在回调方面会遇到一些问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 2020-06-08
    相关资源
    最近更新 更多