restrict closing change requests to change_manager role

RBlor
Mega Guru

i need help. i was tasked to restrict closing change requests to those with change_manager role but i cant seem to get it right. 

 

function onCondition() {
// Get the current user's roles
var userRoles = gs.getUser().getRoles();

// Check if the user is a Change Manager
if (userRoles.indexOf('change_manager') == -1) {
    // If the user is not a Change Manager, make the State field read-only
    g_form.setReadOnly('state', true);
} else {
    // If the user is a Change Manager, make the State field editable
    g_form.setReadOnly('state', false);
}
}

 

 I have the above script in teh ui policy on execute if true but it seems to restrict other states as well.  

1 ACCEPTED SOLUTION

Bhavya11
Kilo Patron

Hi @RBlor 

 

above script wont work due to the below code: gs - The scoped GlideSystem (referred to by the variable name 'gs' in any server-side JavaScript) API provides a number of convenient methods to get information about the system, the current logged in user, etc.

 

var userRoles = gs.getUser().getRoles();

 

update UI policy script as below

 

 

function onCondition() {
if (g_user.hasRoleExactly('change_manager')){
    //  If the user is a Change Manager, make the State field editable
    g_form.setReadOnly('state', false);
} else {
    //If the user is not a Change Manager, make the State field read-only
    g_form.setReadOnly('state', true);
}
}

 

 

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

Thanks,

BK

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

View solution in original post

4 REPLIES 4

Not applicable

gs or "GlideSystem" is server-side only.

 

Try the client-side equivalent

 

g_user.hasRoles('change_manager')

 

or

g_user.hasRoleExactly('change_manager')

Bhavya11
Kilo Patron

Hi @RBlor 

 

above script wont work due to the below code: gs - The scoped GlideSystem (referred to by the variable name 'gs' in any server-side JavaScript) API provides a number of convenient methods to get information about the system, the current logged in user, etc.

 

var userRoles = gs.getUser().getRoles();

 

update UI policy script as below

 

 

function onCondition() {
if (g_user.hasRoleExactly('change_manager')){
    //  If the user is a Change Manager, make the State field editable
    g_form.setReadOnly('state', false);
} else {
    //If the user is not a Change Manager, make the State field read-only
    g_form.setReadOnly('state', true);
}
}

 

 

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

Thanks,

BK

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

thank you. so should i make condition state is review so it applies to changes to closed? I am trying to make other not able to close change requests if not change managers

Bhavya11
Kilo Patron

Hi @RBlor 

 

please add appropriate condition so that it should run only and apply the restrictions.

 

Thanks,

BK

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK