Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an old on site CRM system (not Dynamics 365) and need to get the users roles.
Here is one of them. All it returns is a list of all the entities, the the user roles.
On on site restBuilder would certainly help.

function UserSecurityRoles() {
 UserID = Xrm.Page.context.getUserId();
   UserID  =UserID .replace("{","").replace("}",""); 

  var fetchXml =
        "<fetch mapping='logical'>" +
            "<entity name='systemuser'>" +
            "<attribute name='systemuserid' />" +
            "<filter type='and'>" +
            "<condition attribute='systemuserid' operator='eq-userid' />" +
            "</filter>" +
            "<link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
            "<link-entity name='role' from='roleid' to='roleid' alias='r'>" +
            "<filter type='or'>" +
			"<condition attribute='name' operator='eq' value='Accounts' />";
		" </filter>" +
        "</link-entity>" +
        "</link-entity>" +
        "</entity>" +
        "</fetch>";
    
     var users = ExecuteFetch(fetchXml);
}

function ExecuteFetch (originalFetch) {
    var users;
 
    var fetch = encodeURI(originalFetch);

    var serverURL = Xrm.Page.context.getClientUrl();
    var Query = "?fetchXml=" + fetch;
    var req = new XMLHttpRequest();
    req.open("GET", OdataQuery + Query, false);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function () {
        if (this.readyState == 4 /* complete */) {
            req.onreadystatechange = null;
            if (this.status == 200) {
                 users = JSON.parse(this.responseText).d;
                }
            }
            else {
                var error = JSON.parse(this.response).error;
            }
        }
    };
    req.send();
    return users ;


What I have tried:

I have tried numerous methods and have hit a brick wall.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900