- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 11:39 PM
I would like to use multiple "indexOf" in a field map script.
I have created multiple conditions using "if" and "else if".
The first "indexOf" works, but the second and subsequent "indexOf" don't work.
Do you know how to deal with this?
Or if you have an example, I would appreciate it if you could describe it.
Thank you in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2022 12:46 AM
Try as below:
answer = (function transformEntry(source) {
var result = [];
if (source.fieldnameA.indexOf('x') > -1) {
result.push("xxxxx");
if (source.fieldnameB.indexOf('y') > -1) {
result.push("yyyyy");
if (source.fieldnameC.indexOf('z') > -1) {
result.push("zzzzz");
}
return result;
})(source);
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2022 12:16 AM
Hi,
ensure you use toString() on the value you want to search before using indexOf
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2022 12:30 AM
Hi Daiki,
Try using switch case as you have multiple else if. But still you need to check why it's not working in a different conditions, you can add log statement in each else if.