multiple if condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 03:31 PM
Hi guys, I am trying to have the transform script where my source field is string and the target field (target.pcode) is of choice type (7 fields). I need help on how to write this in script in order to evaluate the correct data map between two fields. Thanks
var pdata = source.u_postalcode.toString();
if(pdata == 'AB' || pdata == 'CD' || pdata == 'EF' || pdata == 'GH' || pdata == 'IJ' || pdata == 'KL'|| pdata == 'MN'){
ignore = false;
} else {
ignore = true;
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 03:47 PM
Hello,
What is the issue with what you've provided above?
I'm not understanding what isn't working from that and what you actually need help with, specifically.
If it's a selection field with choices, then as long as the values from this source field are either the back-end value of a related choice or the display value of a related choice, then it's fine as is.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 03:53 PM
I'm not sure whether 'if' condition works in the above mentioned script. And I have given all the target field choice values in the 'if' condition, is it correct to use many 'OR' operators like this. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 04:50 PM
Hi,
To be sure, you can use log statements to see what you're getting for the source field or look at your import document/payload or whatever it is. That part shouldn't be a mystery.
You can use that many || in your if statement as it's all relatively short.
There's other ways to script it as well, but for all intents and purposes, what you have would work fine.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2022 05:11 PM
If the question is to just write the if condition shorter, try below:
var allowed_pdata = ['AB', 'CD', 'EF', 'GH', 'IJ', 'KL', 'MN'];
var pdata = source.u_postalcode.toString();
ignore = allowed_pdata.includes(pdata);