Concatenate certain values from two or more string fields into one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:52 AM
Hi,
I am trying to achieve the following:
Field A (Country): INDIA
Field B (Location): Pune
Field C (Asset Tag): GM110022
Concatenated Field: IN_Pune_GM110022
I know the calculated field type can give me "INDIA_Pune_GM110022", however, I want only the first two characters from Field A.
Guidance appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:57 AM
Please try with below script in business rule,
(function executeRule(current, previous /*null when async*/) {
// Get the values of the three fields
var country = current.getValue('Country');
var location = current.getValue('Location');
var assetTag = current.getValue('Asset Tag');
// Concatenate the values with underscores
var concatenated = country.substring(0,2) + '_' + location + '_' + assetTag;
// Set the value of the Concatenated Field
current.setValue('Concatenated Field', concatenated);
})(current, previous);
n the script above, we're using the substring() function to get the first two characters of the Country field. The getValue() function is used to retrieve the values of the fields, and setValue() is used to set the value of the Concatenated Field.
Make sure to replace the field names with the actual names of the fields in your ServiceNow instance. Also, you can adjust the separator used between the fields by changing the underscore character in the concatenated variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 02:38 AM
Thanks this worked for me. I used a Before business rule, insert and update selected

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 06:02 AM
Hi @gauravmahendru ,
You can use following script .
(function calculatedFieldValue(current) {
var fullString = current.country.toString().substring(0, 2) + '_' + current.location.toString()+'_'+current.asset_tag.toString();
return fullString;
})(current);
If this helped you please mark it helpful / mark it correct answer.
Thank you
Nitin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 04:42 AM
Hi, @gauravmahendru . Thank you for marking my response as helpful. Please consider marking it as the answer if my reply helped you resolve the issue. This will help the community.
Thank you
Nitin