Auto Populate location field on case form with contacts location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:15 AM
Hi All,
I have a requirement to auto populate on the case form to auto populate the location field with the location of the contact who is selected in the contact field.
Does anyone know how to do this? Or have a script for this?
Kind Regards,
Luke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:34 AM
Hi @Luke James ,
You can achieve this using catalog client script. But for that in users profile (sys_user table) contact & accounts fields should be available.
Use g_user.userID() to get the logged in users sys_id.
Or you can use new platform capability: https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:43 AM
Hi @Community Alums ,
Thanks for your response. This would need to be on the actual case form though when an agent is filling out a case. Not through a catalog request itself.
Any idea on how to do that?
Kind Regards,
Luke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:47 AM
@Luke James You need to create an onChange client script on the case form for Contact field. Inside the script you can use
var contact = g_form.getReference('contact',contactCallback);
function contactCallback(contact){
g_form.setValue('location',contact.location);
}
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:52 AM
@Luke James Here is how you should configure the onChange client script on the case form.
Here is the script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var contact = g_form.getReference('contact', contactCallback);
function contactCallback(contact) {
g_form.setValue('location', contact.location);
}
}
Hope this helps.