Help me out of Working with Optionsets for example letz say I have an optionset with values A1,A2,A3,A4 and based on User security role I want to show A1,A2 to User 1 and A3,A4 to User 2
function onLoad() {
var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.roles;
var userHasRole1 = false;
var userHasRole2 = false;
// Replace "Role1 GUID" and "Role2 GUID" with the GUIDs of the roles you want to check
var role1GUID = "Role1 GUID";
var role2GUID = "Role2 GUID";
// Check if the current user has Role 1
for (var i = 0; i < currentUserRoles.length; i++) {
if (currentUserRoles[i].id === role1GUID) { // Use currentUserRoles[i].id here
userHasRole1 = true;
break;
}
}
// Check if the current user has Role 2
for (var i = 0; i < currentUserRoles.length; i++) {
if (currentUserRoles[i].id === role2GUID) { // Use currentUserRoles[i].id here
userHasRole2 = true;
break;
}
}
// Get the option set field
var optionSetField = Xrm.Page.getAttribute("new_optionsetfieldname");
if (userHasRole1) {
// Set the option set values for User 1
optionSetField.setValue(100000000); // A1
optionSetField.setValue(100000001); // A2
} else if (userHasRole2) {
// Set the option set values for User 2
optionSetField.setValue(100000002); // A3
optionSetField.setValue(100000003); // A4
}
}