Transform maps - how to set *some* target fields to false when the source is null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 12:21 AM - edited ‎10-17-2023 12:22 AM
Basic question, but has defeated me so far
Importing data (from CSV) and transforming to scoped application custom table
I have fields in the imported data that map to 5 choice fields with 2choices
For these five fields only - when the source is TRUE I need the target field set to True, if the source is NULL / FALSE I need the target field to be set to False. Any other source fields that are null are not to overwrite the target
I cannot work out how to only do this for some fields
Any thoughts on how to proceed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 12:28 AM
How you did it? Are you trying to achieve this via script if so can you provide more details of it.
Best regards
Suyog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 12:44 AM
I didn't used the script. Can someone please help with how to script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 01:08 AM
On high level this is something you can try, I will try it at my end and add here, meantime you can use script of field level mapping
if(source.field_name == true){ //replace field name with your source field mapping
return true;
}
else if(source.field_name == false || source.field_name == '')
{
return true;
}
Best regards
Suyog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 01:03 AM
you can use onBefore transform script for this
Don't have field map for these 5 fields which are choices as we will be using onBefore script for that
Something like this
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
if(source.u_field == 'TRUE'){
target.field1 = true;
target.field2 = true;
target.field3 = true;
target.field4 = true;
target.field5 = true;
}
else if(source.u_field == 'FALSE'){
target.field1 = false;
target.field2 = false;
target.field3 = false;
target.field4 = false;
target.field5 = false;
}
})(source, map, log, target);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader