How to get display value of a reference field?

Yaalini Sakthiv
Giga Contributor

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?

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

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

GlideAjax Example Cheat Sheet

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,Can you please help me with the code?

@Yaalini Sakthivel 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader