How to add Role in condition in Onload client script??

Santosh Kallim1
Giga Contributor

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');
}
}

5 REPLIES 5

Tony Chatfield1
Kilo Patron

you have a couple of options
if(g_user.hasRoleFromList('a_user_role'))
if(g_user.hasRole('itil')

 

if(state == 4)

and 

if(g_user.hasRole('itil')

 

I need to validate both the condition at same time ... please suggest

if (state == 4 && g_user.hasRole('itil') ) {

//Your logic here

}

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

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.