Record Producer script to populate record with reference field

servicetrout
Tera Expert

Have a record producer set up with Approver field populated with a catalog client script containing:

function onChange(control, oldValue, newValue, isLoading) {

  var dept = g_form.getReference("u_requestordept");

  var dbo = dept.PrimeContact;

  g_form.setValue("u_deptapprover", dbo);

}

The approver's name shows up on the form but not in the table's u_deptapprover field after the submit.

Added this code to the "What it will contain" script:

current.u_deptapprover= producer.u_deptapprover.getDisplayValue();    

But still nothing appears in the table field.   If I set the table field to be type string, the approver's name shows up.   Not so with a reference field.

How do I set the table reference field with the value in the form?

Or, what do I need in the script to load the original reference field vale to the table?

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

When both fields are of reference type, it should be



current.u_deptapprover= producer.u_deptapprover;  


View solution in original post

4 REPLIES 4

Abhinay Erra
Giga Sage

When both fields are of reference type, it should be



current.u_deptapprover= producer.u_deptapprover;  


Thank you.


stefan_ojeblom
ServiceNow Employee
ServiceNow Employee

Hi Glenn,



The getDisplayValue() function will return the column label of the field that has been set as Display = true in the dictionary entries on the referenced table.


This will normally be set out of the box for ServiceNow tables but you have to set it yourself if/when you create a custom table.



Do this;



1. Open the table you are referencing in "configuration mode"


find_real_file.png


Look at the Display value column and set the value to true for the column label you would like to be used as the value to appear in the reference field;


find_real_file.png


Thank you.