Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

The reference field is not populated if name or displayValue=true field has empty value.

Nancy19
Giga Contributor

Hello folks,

I have developed an integration where I need to relate my records to the cmdb_ci table, for that, I have added the reference field to my table referencing the cmdb_ci. I populate the value in the reference field from my code where I add the sys_id of the cmdb_ci record to my reference type field and when I view the record in form view I get the "name"  of cmdb_ci record in the field type. For eg.

find_real_file.png

 Now I faced and issue when the "name" field of the cmdb_ci record did not have any value ie it was empty. Even if I get the correct sys_id in my code and it is assigned to this field, when I go to the form view I find that the value is empty. I also tried to assign the value manually when the name was empty but found no luck. 

find_real_file.png

I know that we can change the display value for a table and then that value is shown in referenced field. But I do not want the user to do that configuration manually ie I want the solution to be part of my application code. 

Does anyone know the reason if the name field or the field marked as displayvalue=true is empty then why does it not allow to add the refernce value. And if so what would be the workaround.

Thanks,

Nancy

1 ACCEPTED SOLUTION

Hi,

 

Try below code

 

var gr = new GlideRecord('target_table');

gr.initialize()

.

Inserting other fields

.

.

gr.cmdb_reference_field = source_table_gr.sys_id.toString(); // getting this from ablove

gr.insert();

 

 

Thanks,

Kunal

View solution in original post

8 REPLIES 8

Hi,

 

try below to set display value

 

var res = source_table_gr.sys_id.toString();

gr.cmdb_reference_field.setDisplayValue(res);

 

Thanks,

Kunal

Hi,

Will that be a valid scenario that name of cmdb_ci record would be empty?

Regards
Ankur

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

It is a case of bad CMDB, but ServiceNow does not restrict creating records with empty Name, so we need to handle it specifically

Hi Nancy,

ideally there should be only 1 column with display=true

Is this issue resolved or still help is required?

Regards
Ankur

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