0

我只想向具有系统管理员的用户显示“运行工作流程”功能区按钮,因此我使用以下 JS 在我的 Dynamics 解决方案中运行良好:

function getrolesarray(formcontextfromribbon) {
    var Globalcontext = Xrm.Page.context;
    var strFirstThree = Globalcontext.getVersion().substring(0, 3);
    var sameunit = true;
    var noclosed_status = true;
    var selview = 0;

    var roleid = Globalcontext.getUserRoles();

    var RoleName_concat = "";

    var user_sysadmin_yesno = false;

    var name;
    for (var i = 0; i < roleid.length; i++) {
        var roleID = roleid[i];
        var RoleName = getRoleName_XMLHttp(roleID,strFirstThree);

        RoleName = RoleName.toUpperCase()

        if ((RoleName == 'SYSTEM ADMINISTRATOR')) {

            user_sysadmin_yesno = true;
             
            break;
        }

    }

    return user_sysadmin_yesno;


}

function getRoleName_XMLHttp(roleID,strFirstThree) {
    var roleName = null;
    var param = roleID.toString().replace("{", "").replace("}", "");
    var ajaxurl = Globalcontext.getClientUrl() + "/api/data/v" + strFirstThree + "/roles(" + param + ")?$select=_businessunitid_value,name,roleid";
    var req = new XMLHttpRequest();
    req.open("GET", ajaxurl, false);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var result = JSON.parse(this.response);
                var _businessunitid_value = result["_businessunitid_value"];
                var _businessunitid_value_formatted = result["_businessunitid_value@OData.Community.Display.V1.FormattedValue"];
                var _businessunitid_value_lookuplogicalname = result["_businessunitid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
                var name = result["name"];
                var roleid = result["roleid"];
                roleName = result["name"];
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();

    return roleName;
}

如果我尝试在第 2 行使用以下内容更新已弃用的表单:

var Globalcontext = Xrm.Utility.getGlobalContext();

它将返回未定义,如何使其工作?

4

1 回答 1

1

打开CRM,打开开发者工具(按F12),选择“Console”,在控制台输入Xrm.Utility,回车,展开你得到的对象,检查getGlobalContext扩展是否存在。

在此处输入图像描述

经过检查,我发现它不存在,并且必须仅适用于 9.0 及更高版本。

于 2020-06-23T02:14:54.813 回答