- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 03:59 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 09:05 PM
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();
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 08:50 PM - edited 07-11-2024 09:36 PM
gs or "GlideSystem" is server-side only.
Try the client-side equivalent
g_user.hasRoles('change_manager')
or
g_user.hasRoleExactly('change_manager')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2024 09:05 PM
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();
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2024 09:32 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2024 08:55 PM
Hi @RBlor
please add appropriate condition so that it should run only and apply the restrictions.
Thanks,
BK