Abort transform if all rows are empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 04:55 PM
Hello,
I have enabled "copy empty fields" on my transform map. I know this means that all empty values will be copied on the instance.
Thus, is there a way for me to check the value of the columns first and ignore the transform if there is a column where all values are empty on the file being uploaded.
Like for example, in this file, all rows for short desc is empty. I want for the transform to be aborted if the file being loaded is like this one.
Number | Short Desc | Desc |
111 | test1 | |
222 | test2 | |
333 | test3 |
Appreciate all the help. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 07:50 PM
so basically when transform map runs it runs row by row.
You can use onStart transform script and check this
1) query the import set table with the current set
2) check if all records have empty short description
3) if yes then abort the transformation
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 10:46 PM
Hello @Ankur Bawiskar , thanks so much for your response. Do you have a sample script that I can use? I basically need to check all fields on the staging table and not just short description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 11:17 PM
something like this
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var isEmpty = false;
var gr = new GlideRecord(source.sys_class_name);
gr.addQuery("sys_import_set", source.sys_import_set);
gr.query();
while (gr.next()){
if(gr.u_short_desription == '' || gr.u_field == ''){
isEmpty = true;
break;
}
}
if(isEmpty){
ignore = true;
log.info("Entire transformation will be ignored");
}
})(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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 11:59 PM
Hello @Ankur Bawiskar, does this code mean it will get the current import set?
var gr = new GlideRecord(source.sys_class_name);
gr.addQuery("sys_import_set", source.sys_import_set);