How to truncate a value?

User205031
Tera Contributor

Hi,

There is reference field which refers an application table which contains value as 'ABC XYZ'. So when a user selects a value from that field, the reference field should display value as 'ABC'. It should display values without 'XYZ' keyword.

Is it possible to achieve?

Thanks in advance!

1 ACCEPTED SOLUTION

No you cannot change the display value of the reference field apart from the fields which are present in your base table. So if you want to display something else then you might have to create a custom field in your table and populate the value of first half of the application there via some script and then set the display value of the custom field to true. 

Post this you when you will select the same filed as reference in your catalog item then it will show only ABC.

Below thread might provide you more clarity on the same. Read the answer provided by Pradeep Sharma.

https://community.servicenow.com/community?id=community_question&sys_id=6535afb9dbf567005d782183ca961978

 

Please mark this answer as correct and helpful.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

View solution in original post

5 REPLIES 5

Mohit Kaushik
Mega Sage
Mega Sage

Hi There,

Reference field display you might not be able to change it. But you can create a new field and populate the value the desired value there.

For ex: You can write an onchange Catalog client script for this.

var ref = g_form.getDisplayBox('your reference field name').value;

g_form.setValue('new field name',ref.split(' ')[0]);

 

Please mark this correct and helpful as per impact.

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hi Mohit,

We want to display the value in the reference field itself. We do not want to populate it in another field. Can't we display it in the same field?

Thanks!

No you cannot change the display value of the reference field apart from the fields which are present in your base table. So if you want to display something else then you might have to create a custom field in your table and populate the value of first half of the application there via some script and then set the display value of the custom field to true. 

Post this you when you will select the same filed as reference in your catalog item then it will show only ABC.

Below thread might provide you more clarity on the same. Read the answer provided by Pradeep Sharma.

https://community.servicenow.com/community?id=community_question&sys_id=6535afb9dbf567005d782183ca961978

 

Please mark this answer as correct and helpful.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Thanks Mohit! We tried this approach and it working fine.