How to detect if user has a certain role on the Catalog Item?

mattmg
Tera Guru

Hey,

 

I have a requested by field on the form (refferenced to sys_user table), which based on it's default value detect user (javascript:gs.getUserID()) - that works fine. 

 

Now I would like to create another field

'Does user has a 'itil' role?', how on the Catalog Item/Record producer can query for this and push the outcome to that new field?

 

TIA

Matt

1 ACCEPTED SOLUTION

@mattmg 

try to use onLoad catalog client script

Ensure you perform testing by logging in and not impersonating

function onLoad() {
    if (g_user.hasRole('itil'))
        g_form.setValue('variable', 'Yes');
    else
        g_form.setValue('variable', 'No');
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

so it is from currently logged, however I have variable 'created_by' that detects user based on default value - javascript:gs.getUserID()

Ankur Bawiskar
Tera Patron
Tera Patron

@mattmg 

Please use the approach shared by @Tai Vu 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader