How to add Role in condition in Onload client script??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2019 11:50 PM
Hello,
I have created the below code, I need to add role condition.
example: If user has role 'ABCD' then execute this.
Can anyone help
function onLoad() {
var state = g_form.getValue('state');
if(state == 6) {
g_form.removeOption('state', '3');
}
if(state == 4) {
g_form.removeOption('state', '-5');
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2019 11:55 PM
you have a couple of options
if(g_user.hasRoleFromList('a_user_role'))
if(g_user.hasRole('itil')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2019 12:06 AM
if(state == 4)
and
if(g_user.hasRole('itil')
I need to validate both the condition at same time ... please suggest

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2019 12:11 AM
if (state == 4 && g_user.hasRole('itil') ) {
//Your logic here
}
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2019 01:01 AM
Hi,
You can try like this
if (g_form.getValue("state")==4 && g_user.hasRole("itil")) {
//add your logic here.
}
Mark the answer as correct/helpful if this works.