Hi
I want to hide a tab on a form if the user does not have a certain security role. I am currently using this JS to get all the roles of the current user. How do I then extend this to show/hide the tab? At the moment, I have it as an on load function and it returns a series of alerts showing each role the user has.
function GetUserRoles() {
var roles = Xrm.Page.context.getUserRoles();
for (var i = 0; i < roles.length; i++) {
GetRole(roles[i]);
}
alert(roles);
}
function GetRole(roleid) {
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/RoleSet?$select=Name&$filter=RoleId eq guid'" + roleid + "'";
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", oDataSelect, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retrieveReq.onreadystatechange = function () {
GetRoleData(this);
};
retrieveReq.send();
}
function GetRoleData(retrieveReq) {
if (retrieveReq.readyState == 4) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
alert(retrieved.results[0].Name);
}
}
}
Thanks in advance.
*This post is locked for comments