Dynamics CRM自定义表单事件Javascript出错
Error in Dynamics CRM Custom form Event Javascript
我正试图在Dynamics CRM中的窗体上制作一个按钮,以便单击该按钮显示一个对话框。我使用的JS代码如下:
function addButton(attributename) {
if (document.getElementById(attributename) != null) {
var sFieldID = "field" + attributename;
var elementID = document.getElementById(attributename + "_d");
var div = document.createElement("div");
div.style.width = "19%";
div.style.textAlign = "right";
div.style.display = "inline";
elementID.appendChild(div, elementID);
div.innerHTML = '<button id="' + sFieldID + '" type="button" style="margin-left: 4px; width: 100%;" ><img src="/_imgs/ico_16_4210.gif" border="0" alt="Dial this number"/></button>';
document.getElementById(attributename).style.width = "80%";
document.getElementById(sFieldID).onclick = function () {onbuttonclick(); };
}
}
function onbuttonclick() { alert('Hi');}
该函数是在JS Web资源中编写的,该资源由联系人实体的表单加载事件触发。每当表单加载事件被触发时,我都会在对话框中收到以下错误:
此字段的自定义事件发生错误。字段:窗口事件:加载错误:未定义
请引导我走向决议。该代码取自一个示例。
这只是意味着您的JavaScript中有一个错误。
一个更好的解决方案是使用一个功能区按钮,并让该功能区按钮调用javascript,而不是扰乱DOM(这是不受支持的)。将以下代码放入ribbondiffxml中:
<Actions>
<JavaScriptFunction Library="$[js library name]" FunctionName="[js function name]" />
</Actions>
具体来说,这应该进入CommandDefinitionNode
以下是我如何通过javascript:打开对话框的示例
Ribbon.openDialogProcess = function (dialogId, EntityName, objectId) {
var url = Xrm.Page.context.getClientUrl() +
"/cs/dialog/rundialog.aspx?DialogId=" +
dialogId + "&EntityName=" +
EntityName + "&ObjectId=" +
objectId;
var width = 400;
var height = 400;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
window.open(url, '', 'location=0,menubar=1,resizable=0,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + '');
}
所以只需在RibbonDiffXML中调用该方法。
相关文章:
- javascript中的数组出错
- 使用javascript在MVC中查找网格长度时出错
- 将javascript代码转换为jquery代码时出错
- 将对象的列表c#传递给javascript:undefined变量时出错
- 使用 javascript 打开新的浏览器窗口时出错
- 比较Javascript中的两个字符串时出错
- 扩展 JavaScript Promise 时出错
- css3转换和javascript出错
- 找不到容器:goog.Disposable.instances _在为javascript工具使用泄漏查找器时出错
- 我的Javascript代码出错
- 使用Javascript将多条记录插入SQLite数据库时出错
- 在Javascript中访问Razor布尔变量时出错
- Applescript JavaScript“;行尾但找到标识符“;控制Google Chrome时出错
- 使用PHP和Javascript在函数内部传递alphaneumeric值作为参数时出错
- 在Tomcat中运行Javascript代码时出错
- Facebook Javascript SDK:发布到提要时验证访问令牌时出错
- PHP 和 googleMap API 中的 javascript 出错
- 如何在使用javascript出错时重新加载页面
- Dynamics CRM自定义表单事件Javascript出错
- 在野营应用程序中调用Javascript出错