Dynamic Crm页面弹小窗口做页面赋值

  • 2021-11-24
  • Admin

背景:公司要求在CRM窗口上面做弹窗 做页面修改,

官方写法

var DialogOption = new Xrm.DialogOptions;

DialogOption.width = document.body.clientWidth * 0.9;
DialogOption.height = document.body.clientHeight * 0.9;
Xrm.Internal.openDialog(url, DialogOption, null, null, function (returnValue) {

console.log('调用成功 返回值:' + returnValue); //这里就可以接收到弹窗上面传过来的数组
});

弹出框中的返回值设置

var ReturnRlt = []; //先建一个数组 用于在小窗口上面存值 后面放页面上

 ReturnRlt["name"] = obj.result.name;

Mscrm.Utilities.setReturnValue(oReturn);

我的写法

1、这里是按钮的click事件

function AccontSerachBtn_Click() {

    var w_height = $(parent.parent.window).height() / 2 + 300;
    var w_width = $(parent.parent.window).width() / 2 + 200;
    var dlg_args = new Object();
    dlg_args.entityid = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");
    dlg_args.logicalname = Xrm.Page.data.entity.getEntityName();
    var customName = Xrm.Page.getAttribute("name").getValue();
    dlg_args.CusName = customName;

    dlg_args.parentheight = w_height;
    var clientUrl = Xrm.Page.context.getClientUrl();

    var addParams = "id=" + dlg_args.entityid + "&name=" + dlg_args.CusName; 
    //var url = clientUrl + "/WebResources/account?id=" + dlg_args.entityid + "&name=" + dlg_args.CusName +"";
    //var url = clientUrl + "/WebResources/new_SerachAccount?id=" + dlg_args.entityid;
    var url = clientUrl + "/WebResources/new_SerachAccount?Data=" + encodeURIComponent(addParams);


    //dlg_args.Xrm2 = Xrm;
    var oUrl = parent.Mscrm.CrmUri.create(url);
    var dialogwindow = new parent.Mscrm.CrmDialog(oUrl, dlg_args, w_width, w_height, false, false, "status:no;", null);
    dialogwindow.setCallbackReference(function (result) {
        //客户名称
        Xrm.Page.getAttribute("name").setValue(result["name"]);
        //企业ID
        var companyId = result["id"].toString();
        Xrm.Page.getAttribute("new_company_id").setValue(companyId);
       
        //Xrm.Page.data.refresh();
    });
    dialogwindow.show();
}

2、这里是弹窗页面传值

  var ReturnRlt = [];

 //名称
   ReturnRlt["name"] = obj.result.name;

  ReturnRlt["id"] = obj.result.id;

 Mscrm.Utilities.setReturnValue(ReturnRlt);
                closeWindow();

这样写完 就可以把弹窗页面上面的值传到CRM窗体上面了

原文:https://blog.csdn.net/loginnamess/article/details/121524134

联系站长

QQ:769220720