Saturday, March 31, 2018

Check User Specific Role - Web API - Dynamics CRM 365

In this post, I am going to demonstrate how to check that current logged in user has specific role or not in Dynamics CRM 365 using JavaScript & Web API.


function IsRoleExist(RoleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
        if (GetRoleName(userRoleId) == RoleName) {
            return true;
        }
    }
    return false;

}

function GetRoleName(RoleId) {
    var select = "roles(" + RoleId + ")?$select=name";

    var result = AWXRM.WebAPISelectVersion(select, "8.2");
    var Rolename = result["name"];
    return Rolename;

}

function OnLoad() {

var Role_Admin = "System Admin_1";
var IsRoleExist = null;

   if (IsRoleExist(Role_Admin))
            IsRoleExist = true;
        else
            IsRoleExist = false;
}

Dependency:
Need this library to be included in form load / page load
AWXRMLibrary


㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC)
LinkedIn



Asp.Net MVC (5) - Exception Filter - HandleError

Applicable on Asp.Net MVC5 HandleError Filter This belongs to Exception Filters category (Authentication Filter, Authoriz...