none
求CRM4.0 如何获得角色id? RRS feed

  • 问题

  • 请问  如何获得已知角色的id并与当前用户的角色id比较是否一致?  我是想写在onsave事件中  请高手帮忙!

    详细:已知一角色名 sales(自己创建的)  当onsave时  判断当前用户角色id是否与sales角色id一致?  如何做到?

    2010年9月20日 8:11

答案

  • xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
                    " <soap:Body>" + GenerateAuthenticationHeader() +
                        " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" +
                            " <q1:EntityName>role</q1:EntityName>" +
                            " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
                                " <q1:Attributes>" +
                                    " <q1:Attribute>name</q1:Attribute>" +
                                " </q1:Attributes>" +
                            " </q1:ColumnSet>" +
                            " <q1:Distinct>false</q1:Distinct>" +
                            " <q1:LinkEntities>" +
                                " <q1:LinkEntity>" +
                                    " <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
                                    " <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
                                    " <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
                                    " <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
                                    " <q1:JoinOperator>Inner</q1:JoinOperator>" +
                                    " <q1:LinkEntities>" +
                                        " <q1:LinkEntity>" +
                                            " <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
                                            " <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
                                            " <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
                                            " <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
                                            " <q1:JoinOperator>Inner</q1:JoinOperator>" +
                                            " <q1:LinkCriteria>" +
                                                " <q1:FilterOperator>And</q1:FilterOperator>" +
                                                " <q1:Conditions>" +
                                                    " <q1:Condition>" +
                                                        " <q1:AttributeName>systemuserid</q1:AttributeName>" +
                                                        " <q1:Operator>EqualUserId</q1:Operator>" +
                                                    " </q1:Condition>" +
                                                " </q1:Conditions>" +
                                            " </q1:LinkCriteria>" +
                                        " </q1:LinkEntity>" +
                                    " </q1:LinkEntities>" +
                                " </q1:LinkEntity>" +
                            " </q1:LinkEntities>" +
                        " </query>" +
                    " </soap:Body>" +
                "</soap:Envelope>" + "";

    xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    resultXml = xmlHttpRequest.responseXML;
    var roles = resultXml.selectNodes("//BusinessEntity/q1:name");


    var roleAllowList = [
         '系统管理员'   ];


    if (roles != null) {
        for (i = 0; i < roles.length; i++) {
            for (var j = 0; j < roleAllowList.length; j++) {
                if (roles[i].text == roleAllowList[j]) {
                    bVisible = true;
                    break;
                }
            }

            if (bVisible)
                break;
        }
    }

    2010年9月20日 10:24
  • http://www.cnblogs.com/mscrm/articles/1054783.html
    2010年9月21日 2:48

全部回复

  • xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
                    " <soap:Body>" + GenerateAuthenticationHeader() +
                        " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\" xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" +
                            " <q1:EntityName>role</q1:EntityName>" +
                            " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
                                " <q1:Attributes>" +
                                    " <q1:Attribute>name</q1:Attribute>" +
                                " </q1:Attributes>" +
                            " </q1:ColumnSet>" +
                            " <q1:Distinct>false</q1:Distinct>" +
                            " <q1:LinkEntities>" +
                                " <q1:LinkEntity>" +
                                    " <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
                                    " <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
                                    " <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
                                    " <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
                                    " <q1:JoinOperator>Inner</q1:JoinOperator>" +
                                    " <q1:LinkEntities>" +
                                        " <q1:LinkEntity>" +
                                            " <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
                                            " <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
                                            " <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
                                            " <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
                                            " <q1:JoinOperator>Inner</q1:JoinOperator>" +
                                            " <q1:LinkCriteria>" +
                                                " <q1:FilterOperator>And</q1:FilterOperator>" +
                                                " <q1:Conditions>" +
                                                    " <q1:Condition>" +
                                                        " <q1:AttributeName>systemuserid</q1:AttributeName>" +
                                                        " <q1:Operator>EqualUserId</q1:Operator>" +
                                                    " </q1:Condition>" +
                                                " </q1:Conditions>" +
                                            " </q1:LinkCriteria>" +
                                        " </q1:LinkEntity>" +
                                    " </q1:LinkEntities>" +
                                " </q1:LinkEntity>" +
                            " </q1:LinkEntities>" +
                        " </query>" +
                    " </soap:Body>" +
                "</soap:Envelope>" + "";

    xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    resultXml = xmlHttpRequest.responseXML;
    var roles = resultXml.selectNodes("//BusinessEntity/q1:name");


    var roleAllowList = [
         '系统管理员'   ];


    if (roles != null) {
        for (i = 0; i < roles.length; i++) {
            for (var j = 0; j < roleAllowList.length; j++) {
                if (roles[i].text == roleAllowList[j]) {
                    bVisible = true;
                    break;
                }
            }

            if (bVisible)
                break;
        }
    }

    2010年9月20日 10:24
  • 此字段自定义事件出错

    字段 window

    事件 onload

    错误:'xmlHttpRequest' 未定义

    2010年9月21日 2:43
  • http://www.cnblogs.com/mscrm/articles/1054783.html
    2010年9月21日 2:48