How to set default value of user manager

Kifrez
Kilo Guru

Hi everyone,

Could you please assist me how to set default value of a variable?
I need user 2's manager to be the default value (Screenshot below)
This script is only get user who is opening the form.
Thanks in advanced for your assistance.

javascript:gs.getUser().getManagerID()

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

If you want to set default value then set for both the variables

If on_behalf_of is auto-populated with logged in user then

This should work for the manager variable

Is that not working as expected? Did you check logged in user has Manager or not

javascript:gs.getUser().getManagerID()

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi.

Default value will only work when form loads and will take value of the logged in user's manager.

Since you require Manager to be populated on User 2 you would require onChange client script for this

Sample below

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ref = g_form.getReference('on_behalf_of',callBack);
}

function callBack(ref){

if(ref.manager){
g_form.setValue('manager',ref.manager); 
}

}

Regards
Ankur

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

hi Ankur, 

Yes, it will work when the form loads.

I will need to set something when the form loads because on_behalf_of still auto populated by javascript:gs.getUserID()

Hi Freddy,

 

If the field is autopopulated then you can use onLoad client script with same logic

Hi,

If you want to set default value then set for both the variables

If on_behalf_of is auto-populated with logged in user then

This should work for the manager variable

Is that not working as expected? Did you check logged in user has Manager or not

javascript:gs.getUser().getManagerID()

Regards
Ankur

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