- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 09:31 PM
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()
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 09:58 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 09:37 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 09:51 PM
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()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 09:55 PM
Hi Freddy,
If the field is autopopulated then you can use onLoad client script with same logic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 09:58 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader