How to set reference field value by using setValue()

DhanunjayaB0597
Tera Contributor

var user=g_form.getReference('requested_for',doAlert);
function doAlert(user)
{
g_form.setValue('manager',user.manager);
}

By using this script I got sys_id but actually I need the name of manager how can I get 

1 REPLY 1

Paul Curwen
Giga Sage

Try using:

 

g_form.setValue('manager',user.manager.name);

 

Also other advice:

 

1. Rather than using getReference with a callback, consider doing this using GlideAjax and a Script Include ( More efficient as getReference will return all the data of the record whereas with GlideAjax you can get the data you want) 

2. You could also get the users manager in a Display Business Rule and store it in scratchpad. That way you can access the scratchpad at anytime whilst on the form. 

 

e.g. g_form.setValue('manager',g_scratchpad.managerName)

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul