How to fetch reference field data in catalog client script or in script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:28 AM
Hi Expertise,
I need to fetch reference field(like caller) data such as location which is stored in sys_user table and then I have to use this location in catalog client script. so please could anyone suggest me how to achieve this one. I tried getReference method but it is not working.
Awaiting for your response.
Thank You,
Ulka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 01:59 AM
Hi,
then this should work fine
Please check if the alert comes?
var subjectPerson = g_form.getReference('subject_person',doAlert);
function doAlert(subjectPerson)
{
if(subjectPerson.location == 'locationSysId'){
alert('Inside if');
g_form.setValue('fieldName', 'fieldValue');
}
}
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
03-03-2022 02:09 AM
alert is not displaying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 02:17 AM
please share complete script here and the configuration screenshot.
also share the form screenshot
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
03-03-2022 01:29 AM
var subjectPerson=g_form.getReference('subject_person',doAlert);
function doAlert(subjectPerson)
{
if(subjectPerson.getDisplayValue('location') == 'XYZ')
{
g_form.setValue('field Name', subjectPerson.getValue('location'));
}
}
Shakeel Shaik 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 01:42 AM
Hii
Copy and paste the code in your client script:-
var user = g_form.getReference("caller_id",callback);
function callback(user){
if(user.getDisplayValue("location")=="ABC"){
g_form.setValue("field name",user.location);
}
}
Regards,
Imran Ahmad
If Correct Mark as Correct Answer:-
Please Mark Helpful below:-