- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:20 PM
Hello Experts!!
I am trying to fetch location from sys_user table to incident table in a custom field using getRefernce, but it is showing sys_id of the location.
Can anyone help ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:40 PM
If you're using getReference() to fetch the location from the sys_user table to the incident table in a custom field, it's expected that you're seeing the sys_id of the location. This is because getRefernce() retrieves the reference field value, which is typically the sys_id of the referenced record.
var locationSysId = current.location.toString(); // Assuming 'location' is the reference field name
// Fetch the location record
var locationRecord = new GlideRecord('sys_user');
if (locationRecord.get(locationSysId)) {
// Populate the location name in the custom field
current.custom_location_field = locationRecord.getValue('location'); // Assuming 'custom_location_field' is the custom field name
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:28 PM
Hi @Prerna_T location is a reference field in user table, so you need to dot walk location.name to get Name of the location. Also using getReference() is a bad practice, you need to use script include and client script using glideAjax call,
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:29 PM
On which field you are trying to use GetReference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:29 PM
Hello @Prerna_T
when you’re using getReference to fetch information related to a reference field (like pulling location data from sys_user into an incident record), it indeed fetches the entire record, including the sys_id by default. However, if you want to display a human-readable value (like the name of the location) rather than the sys_id, you need to specifically access that field from the fetched record.
use getDisplayValue() or specific field name 'name'
for example :
var locationGR = new GlideRecord('cmn_location');
if (locationGR.get(user.location)) {
current.field_name = locationGR.getDisplayValue(); // Or locationGR.getValue('name');
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 10:35 PM
Hi @Prerna_T ,
You need to change the type of that custom field to reference type and it should reference to location table .then only it will populate display value and if the custom field is of string type consider writing glideAjax .
For more information on glideajax please follow below link -
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
Thanks,
Astik