• Dynamics CRM 365 判断当前登录人是否包含某些角色(JS和C#)


    JS代码:

    // 匹配安全角色
    function matchUserRole(entityRoleNameArray) {
        var isMatch = false;
        if (entityRoleNameArray.length > 0) {
            var strPermitRoleNames = entityRoleNameArray.split(",");
            var userRoleNameArray = new Array();
            // 设置筛选条件
            var filter = "";
            // 获取当前用户安全角色Guid组
            var userRolesGuid = Xrm.Page.context.getUserRoles();
            for (var index = 0; index < userRolesGuid.length; index++) {
                filter += "<value>" + userRolesGuid[index] + "</value>";
            }
    
            var fetchXMLEnableRules = "<fetch mapping='logical'>" +
                "<entity name='role'>" +
                "<attribute name='roleid'/>" +
                "<attribute name='name'/>" +
                "<order attribute='name' descending='false'/>" +
                "<filter type='and'>" +
                "<condition attribute='roleid' operator='in'>" + filter + "'</condition>" +
                "</filter>" +
                "</entity>" +
                "</fetch>";
            var clientURL = Xrm.Page.context.getClientUrl();
            var uri = clientURL + "/api/data/v8.2/roles?fetchXml=" + encodeURI(fetchXMLEnableRules);
            var req = new XMLHttpRequest()
            req.open("GET", encodeURI(uri), false);
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.onreadystatechange = function () {
                if (this.readyState == 4 /* complete */) {
                    req.onreadystatechange = null;
                    if (this.status == 200 || this.status == 204) {
                        var objData = JSON.parse(this.responseText);
                        for (var i = 0; i < objData.value.length; i++) {
                            var objDataItem = objData.value[i];
                            var roleName = objDataItem["name"];
                            if (strPermitRoleNames.indexOf(roleName) != -1) {
                                isMatch = true;
                                return true;
                            }
                        }
                    }
                    else {
                        var error = JSON.parse(this.response).error;
                        Xrm.Utility.alertDialog(error.message);
                    }
                }
            };
            req.send();
        }
        return isMatch;
    }

    C#代码:

    待补充

  • 相关阅读:
    python基础008----Python中类/函数/模块的简单介绍
    linux基础004---用户管理、用户登录注销、系统关机重启
    python基础006----流程控制&推导式&深浅拷贝
    python基础005----字典&集合
    python基础004----列表&元组
    难缠的布隆过滤器,这次终于通透了
    C# 位图BitArray 小试牛刀
    以步步为营的风格解读 Redis分布式锁
    你是不是对MD5算法有误解?
    最适合新手的Redis Cluster搭建过程
  • 原文地址:https://www.cnblogs.com/parkerchen/p/16288823.html
Copyright © 2020-2023  润新知