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

Amit Rao
Tera Expert

Hi Nancy,

You must be using advanced reference qualifier where you're passing sys_id's which you get from script include function.

Do you mind can you share the script include code ?

Nancy19
Giga Contributor

The code is like:

var gr = new GlideRecord('target_table');

gr.initialize()

.

Inserting other fields

.

.

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

gr.insert();

 

And I am not using any advance reference qualifier functionality

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

Kunal thanks for your response, it worked!

But still the value is empty, because the name is empty. I can see the info icon which allows me to go to the parent record. Is there a way where we can change the display value of a table from code i.e fix the column to be used in display for reference field?