Show dynamic text field on catalog item form

Antti Lahti
Giga Contributor

Hello everyone,

I am fairly new to the ServiceNow as we have recently acquired the platform.

 

We have implemented a rather simple form to order Access rights to a certain Business offerings. Business offering is chosen by the end user from a reference list, and I would like to display dynamically a text field that contains information about that particular Business offering. The information I would like to display to the end user is Short_description of that particular Business offering. Can I achieve this using catalog UI policies?

 

I know that the end user can find the exact same information by navigating to the reference record, but, end-users are end-users so I would like to simplify this by popping the information out.

 

Thanks a lot in advance 🙂

 

1 REPLY 1

Punit S
Giga Guru

Yes, you can achieve this using catalog UI policies. Here are the steps to do so:

  1. Create a new UI policy for the catalog item that you want to modify.
  2. In the UI policy, create a new script field and give it a name.
  3. In the script field, write JavaScript code to retrieve the Short description of the Business offering referenced in the catalog item.
  4. Use the following code in the script field to retrieve the Short description of the Business offering:

 

var businessOffering = g_form.getValue('business_offering'); // replace 'business_offering' with the name of your reference field
var gr = new GlideRecord('business_offering_table'); // replace 'business_offering_table' with the name of the table that contains the Short description field
gr.get(businessOffering);
g_form.setValue('short_description', gr.short_description);
​

Save the UI policy.

 

  • This code retrieves the value of the Business offering reference field on the form, uses it to query the Business offering table to retrieve the Short description, and then sets the Short description value in the Short description field on the form.

    Note: Make sure to replace 'business_offering' and 'business_offering_table' with the actual name of your reference field and table name respectively.

Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.

Thanks,
Punit