- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2021 04:53 AM
I have a reference variable for location of the user and another reference variable within the form to display the 'requested for' user. I need to set the default value of the location variable as the location of the user in 'requested for' variable. Is it possible to get this done using the 'Default value' field in the location reference variable? Kindly help!
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2021 05:04 AM
Hi,
default value for location would work only for logged in user
if you are populating requested for user with logged in user then set default value in location variable as this
javascript: gs.getUser().getLocation();
if someone changes requested for then you need to write onChange client script
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
‎04-23-2021 05:04 AM
Hi,
default value for location would work only for logged in user
if you are populating requested for user with logged in user then set default value in location variable as this
javascript: gs.getUser().getLocation();
if someone changes requested for then you need to write onChange client script
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
‎04-23-2021 05:05 AM
Thank you for your prompt response!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2021 05:06 AM
onChange client script to populate if someone changes the requested for
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.clearValue('location'); // location variable name here
}
var ref = g_form.getReference('requested_for', callBackMethod); // requestedFor variable name
}
function callBackMethod(ref){
if(ref.location)
g_form.setValue('location', ref.location); // location variable name here
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2023 06:19 AM
I had a requirement to also set the users current location as the default value in a reference variable. This worked for me as well.
Thank you