How to fetch particular variable details in reference field.

Hrishabh Kumar
Giga Guru

Hi,

I need to create a reference field on "cmdb_ci_cloud_service_account" named : "Product Category".

Product category is going to be reference of "spm_taxonomy_node" table.

 

The reference field populates with the name of the record, but I have a custom request that "description"(one of the attributes of the referenced record) should be populated in the reference field, rather than the record name.

 

example:

Here is the form view of "cmdb_ci_cloud_service_account" table where "Product category" is created.

referenceDrilldown1.PNG

 

Here is the same referenced record from "spm_taxonomy_node".

referenceDrilldown2.PNG

 

Current behaviour : In reference field we get the names ie.. "name" attribute.

Required behaviour: I need the description ie.. "description"(one of the attributes of the referenced record) attribute, in the reference variable in "Product category" field.

 

5 REPLIES 5

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Hrishabh Kumar ,

 

Navigate to the table configuration of the "spm_taxonomy_node" table, and under columns - set display to 'true' for description

KaranChhabra6_1-1687160111677.png

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

Hey I tried the same solution but it is not working, I can still see names in the reference list.

 

I need the description to be shown in the reference variable list.

Right now if I click on the search icon near the reference variable, it opens the list with name attribute, I need it to have Description attribute also. 

Weather we have description field only, or description field along with name field. Both will work.

referenceDrilldown3.PNG

Riya Verma
Kilo Sage
Kilo Sage

Hi @Hrishabh Kumar ,

 

Hope you are doing great.

 

To achieve the desired behavior of populating the "description" attribute instead of the record name in the "Product Category" reference field on the "cmdb_ci_cloud_service_account" table, you can follow these steps:

  1. Go to the "cmdb_ci_cloud_service_account" table definition.

  2. Add a new reference field named "Product Category" to the "cmdb_ci_cloud_service_account" table.

  3. Set the reference table of the "Product Category" field to "spm_taxonomy_node".

  4. Modify the dictionary attribute of the "Product Category" field to use the "description" attribute of the referenced record instead of the default "name" attribute.

Here's an example of how the code snippet would look like in ServiceNow:

// Step 1: Navigate to "cmdb_ci_cloud_service_account" table definition
// and add a new reference field.

// Step 2: Modify the "Product Category" reference field properties.
var productCategoryField = new GlideRecord('sys_dictionary');
if (productCategoryField.get('name', 'cmdb_ci_cloud_service_account.product_category')) {
    productCategoryField.reference = 'spm_taxonomy_node';
    productCategoryField.reference_qual = '';
    productCategoryField.reference_key = 'description';
    productCategoryField.update();
}

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma