try {
var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
var oResult = command.Execute();
if (oResult.Success) {
return oResult.ReturnValue.UserId;
}
}catch(e){
alert("Error while retrieving userid.");
}
return null;
}
function getUserRoles(userId) {
try {
var command = new RemoteCommand("UserManager", "GetUserRoles");
command.SetParameter("userIds", "
var oResult = command.Execute();
if (oResult.Success) {
return oResult.ReturnValue;
}
}catch(e){
alert("Error while retrieving roles.");
}
return null;
}
function userHasRole(userId, roleName) {
result = getUserRoles(userId);
if (result != null) {
var oXml = new ActiveXObject("Microsoft.XMLDOM");
oXml.resolveExternals = false;
oXml.async = false;
oXml.loadXML(result);
roleNode = oXml.selectSingleNode("/roles/role[name='" + roleName + "']");
if (roleNode != null) {
if (roleNode.selectSingleNode("roleid[@checked='true']") != null)
return true;
}
}
return false;
}
function currentUserHasRole(roleName) {
userId = getUserId();
return userHasRole(userId, roleName);
}
//---- Preguntar por el tipo de rol--------------
if( currentUserHasRole('Salesperson') ) {
alert('true');
}else{
alert('false');
}
No hay comentarios:
Publicar un comentario