Transform Map / Transform Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:33 AM
I am creating a transform script on a source field, and I'm wondering if I can add multiple values/entries in the script. Instead of creating multiple lines for each color, add them in one line. If so, what the syntax would be.
For example:
if (source.u_color == 'Black' 'Blue') {
return 'White';
Code:
answer = (function transformEntry(source) {
if (source.u_color == 'Black') {
return 'White';
}
if (source.u_color == 'Blue') {
return 'White';
}
})(source);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:42 AM
Assuming that u_color is just a string field you could just use indexOf to check the string for the value and then do an OR for your if.
var color = ('' + source.u_color);
if (color.indexOf('Black') != -1 || color.indexOf('Blue') != -1) {
return 'White';
}
Not sure you are going to get any better than that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:54 AM
Hi Drew,
It's a choice field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 10:03 AM
Then you can skip the indexOf part since a choice field is a text field with specific values in it. @AnubhavRitolia posted the code you could use. I thought you where going to pass multiple values at a time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 09:58 AM
Hi @MStritt
Can try like below:
if (source.color == 'Black' || source.color == 'Blue') {
return 'White';
}
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023