how can I take the same value of the field assigned to in another field automatically

Fdeveloper
Kilo Guru

Hi,

find_real_file.png

i have to put(get) the same value who exist in the fields (affecté a) in the fields (incident) in this example in the fields (Affecté a) i have "GUERRIER BASTIEN" i should have the same value in the fields "Incident"=> "GUERRIER BASTIEN" automatically is this possible

1 ACCEPTED SOLUTION

Hi, a reference field would return a sys_id, and you will need to get the field display value for the field involved

You have a number of options
GlideAjax to return to query and return the records display value
getReference() to return the entire record and then populate the display value by dot.walking the field, this may have an impact on UI performance
getDisplayBox()

This post has examples of getReference() and getDisplayBox()
https://community.servicenow.com/community?id=community_question&sys_id=1c8a84e8db759b80032a7a9e0f96...

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, are both of these fields references to the same table?
If yes and if this is required in the UI you would use an onChange() against your source field, and simple map the source field to the target.
g_form.setValue('targetField', newValue);

If you don't need to see the value immediately in the UI, IE you can wait till the record is saved to populate the value then you can use a before BR
current.targetField = current.sourceField;

 

 

hi @Tony Chatfield ,

apologize for the delay and thank you for your reply , i try it to create a client script onchange

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var name = g_form.getValue("assigned_to");
g_form.setValue("u_demandeur",name);

}

don't work coorectly in the field i got the sys id of the user not the name how can i fix that, i need to get the same name not the sys id

Hi, a reference field would return a sys_id, and you will need to get the field display value for the field involved

You have a number of options
GlideAjax to return to query and return the records display value
getReference() to return the entire record and then populate the display value by dot.walking the field, this may have an impact on UI performance
getDisplayBox()

This post has examples of getReference() and getDisplayBox()
https://community.servicenow.com/community?id=community_question&sys_id=1c8a84e8db759b80032a7a9e0f96...

Yaswanth_M
Tera Contributor

If both the fields are reference Fields , Just Select Autopopulate in the Record by Dot Walking the Required Field you can see same value which is already assigned