Is there a way to get the value in a dot-walked field and populate another field with that same value?

Steve H2
Kilo Expert

There is a lookup field on a form named assigned_to. When it is populated from the sys_user table (by selecting a name from the lookup list) other fields related to the assigned_to are populated (like assigned_to.employee_number, and assigned_to.street). I want to take the value displayed in the assigned_to.employee_number field and populate another field with that value as well.

Is there some way to code that - copy/get the value displayed in a dot-walked field and put it into another field?

I'd rather not have to create client scripts and script includes to go to the user table, get the record and bring back the values already on the screen, then put them in the other field. But if that is the only way to do it, I just need to know that.

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

If this is a catalog item, you will have to create onchange client script on the lookup variable and plug this code in there

 

var usr= new GlideRecord("sys_user");

usr.addQuery("sys_id",g_form.getValue("variable name goes here"));

usr.query(callBack);

function callBack(usr){

if(usr.next()){

g_form.setValue("variable name goes here",usr.employee_number);

}

}

View solution in original post

8 REPLIES 8

If you want to do it in client script, then you will have to use GlideAjax to get reference field values.

 

Please check below for GlideAjax details

 

https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f96196e

 

Regards,

Sachin

onLoad client script wont work, since it will not trigger when you change the assigned to value. Either you need a onChange Script or use a business rule to do so. Business Rule is pretty easy and better than using client script. But if you really need it to be done from Client sript, you should go for onChange


Please mark this response as correct or helpful if it assisted you with your question.

Create onChange client script and put the code I posted in my previous post

Steve H2
Kilo Expert

Thanks everybody for your interest in this question. Thanks to all of you who replied with suggestions!

We couldn't find a way to copy the value in field that is a .walked reference field. In the end I went with the onChange client script, and used the sys_id of the parent reference field value to do the query in a script include.