How to get display value of a reference field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2022 06:00 AM
I have a field in my catalog form called 'Asset tag' which is a reference field when we choose any value in 'Asset tag' the field called 'Model' is in "Asset tag's reference table' the model value from that field should get autopopulated to my catalog form 'Model name field'. The 'model' field in Asset tag's reference table is also a reference field when I try to autopopulate it gets the sys id of the model record. Now I don't need the sys id I require the name of the model.The script I used is,
function onChange(control, oldValue, newValue, isLoading) {
var asset_tag = g_form.getReference('asset_tag_add', getModel); //getModel is our callback function
}
function getModel(asset_tag) { //reference is passed into callback as first arguments
g_form.setValue('model', asset_tag.model);
}
The above script gives the sysid i need display value of that field
Can anyone help with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2022 06:09 AM
Hi,
why not keep model variable as reference? If you keep then your script will work fine
If you keep it as text then you would require GlideAjax as you cannot dot walk 2 levels
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
‎07-15-2022 06:20 AM
Hi,Can you please help me with the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2022 02:31 AM
I have already shared the link with sample scripts.
You can refer those, learn and develop script on your own. It would be learning for you as well.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader