javascript - 将参数传递给Mscrm.CrmDialog

标签 javascript dynamics-crm showmodaldialog

我使用 Mscrm.CrmDialog 在 MS Dynamics CRM 2013 中显示带有 Web 资源的新对话框。此方法的优点是该对话框也可以在 Firefox、Chrome 等中使用,而 window.showModalDialog 则不能,因为它是已弃用。

无论如何,我需要将参数传递给网络资源。使用 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();
}

可以通过 window.getDialogArguments() 在 Web 资源中访问上述全局声明的变量,如以下示例 html Web 资源所示

<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>

单击“运行”按钮结果:
enter image description here

关于javascript - 将参数传递给Mscrm.CrmDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31002573/

相关文章:

javascript - react-leaflet 太多标记导致页面卡住

javascript - 在 JS 正则表达式中重用捕获组模式

pagination - $top 应该谋杀 odata.nextlink 吗?

javascript - 如何从 BHO 阻止 window.showModalDialog 弹出窗口?

javascript - 你可以推荐哪个用于 mysql 访问的 javascript 库?

powershell - Microsoft Dynamics CRM 4.0:Powershell cmdlet是否可用?

c# - 如何根据Incident Guid获取注解

ipad - 使用 UIModalPresentationFormSheet 的模态视图出现在屏幕外

c# - 回发后使用 MVC C# 显示弹出确认消息

javascript - 在 Node JS 中只读取文件第一行的最有效方法是什么?