Pet*_*ter 2 javascript dynamics-crm showmodaldialog
我使用Mscrm.CrmDialog在MS Dynamics CRM 2013中显示一个带有webresource的新对话框.此方法的优点是此对话框也适用于Firefox,Chrome等,而window.showModalDialog则不支持,因为它已被弃用.
无论如何,我需要将参数传递给webresource.使用window.showModalDialog这没问题但是现在使用Mscrm.CrmDialog时我找不到任何传递参数的方法.构造函数有一个参数'customWindowParameters',但是如何从Web资源访问这些参数?
在您调用对话框(Mscrm.CrmDialog)的脚本中声明全局变量,如:
var variable1 = 5;
var object1 = { Id: 1, name: "SWA" };
function ribbon_OpenDialog() {
var clientUrl = Xrm.Page.context.getClientUrl();
var url = clientUrl + "/WebResources/new_myWebResource.html";
//CRM 2015 SP 1
var dialogwindow = new parent.Mscrm.CrmDialog(parent.Mscrm.CrmUri.create(url), this, 450, 175);
//For CRM less than CRM 2015 SP 1
//var dialogwindow = new Mscrm.CrmDialog(Mscrm.CrmUri.create(url), this, 450, 175);
dialogwindow.show();
}
Run Code Online (Sandbox Code Playgroud)
可以在webresource中访问上述全局声明的变量,window.getDialogArguments()如以下示例html webresource中所示
<html>
<head>
<title></title>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script type="text/javascript">
var dialog;
if (window.getDialogArguments() != null) {
dialog = window.getDialogArguments();
}
var v1 = dialog.variable1;
var o1 = dialog.object1;
function doSomthing() {
alert("variable1= " + v1 + "\n object1.Id=" + o1.Id + "\n object1.name=" + o1.name);
}
</script>
<style type="text/css">
.dvrow {
clear: both;
margin: 2px auto 0 auto;
padding: 10px 0 10px 0;
width: 96%;
}
.headerTitle {
font-family: Segoe UI Light, Segoe UI, Tahoma, Arial;
font-size: 27px;
font-weight: lighter;
}
</style>
</head>
<body>
<form id="formPopup">
<div id="spinner">
</div>
<div class="dvrow">
<div class="headerTitle">
Test dialog Popup
</div>
<div class="row">
<button title="Run" id="btnRun" onclick="doSomthing();" type="button">Run</button>
</div>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
单击运行按钮结果:
