Hi Experts
I used a JavaScript to get logged in users security role using a JavaScript on CRM2015, but now we upgraded to CRM2016. And the form is throwing and error. Below is the code I'm using, please advice.
function FormOnLoad() { var optCtrl = Xrm.Page.ui.controls.get("statuscode"); var CMRole = CheckUserRole("System Administrator"); if (Xrm.Page.ui.getFormType() == 6 && !CMRole) { optCtrl.removeOption(100000000); } } function GetServerUrl() { return Xrm.Page.context.getClientUrl() + "/xrmservices/2011/organizationdata.svc/"; } function CheckUserRole(roleName) { var currentUserRoles = Xrm.Page.context.getUserRoles(); for (var i = 0; i < currentUserRoles.length; i++) { var userRoleId = currentUserRoles[i]; var userRoleName = GetRoleName(userRoleId); if (userRoleName == roleName) { return true; } } return false; } function GetRoleName(userRoleId) { var selectQuery = "RoleSet?$top=1&$filter=RoleId eq guid'" + userRoleId + "'&$select=Name"; var odataSelect = GetServerUrl() + selectQuery; //alert(odataSelect); var roleName = null; $.ajax({ type: "GET", async: false, contentType: "application/json; charset=utf-8", datatype: "json", url: odataSelect, beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { var result = data.d; if (!!result) { roleName = result.results[0].Name; } }, error: function (XmlHttpRequest, textStatus, errorThrown) { //alert('OData Select Failed: ' + odataSelect); } }); return roleName; }
Error Thrown is:
*This post is locked for comments