Transform map script issue -- scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 10:24 PM
Hi Team,
I have requirement where I need to check if a source field is empty in an excel file while import and trigger a notification based on that.
For example: I am receiving Task number(s) in excel which needs to be processed further. Now there are some scenarios where this file could be empty as you can see in attached; in that case I need to trigger a notification to relevant people.
I am seeing an issue where I am not able to read 'Task number' field using onbefore transform map script. If value of Task number is present then onbefore script is working, however if field is empty and we try to read the value by using below and try to print the same, it is not retuning anything.
var task_number = source.u_task_number;
gs.info(task_number);
My assumption is that if file is empty, above code should return empty value/string.
Could someone please redirect me to the right direction and let me know what I am doing wrong?
Best Regards,
Naveen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:14 PM
Please find below actual code which is not working.
var task_id = '';
task_id = source.u_servicenow_task_id;
if(task_id == '' || task_id == null)
{
gs.eventQueue('custom_app_prefix.servicenowTaskUpdate',source);
}
Best Regards,
Naveen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:40 PM
did you check what came in task_id in logs?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:07 PM
var task_number = source.u_task_number;
if (task_number ==null || task_number == undefined || task_number == "") {
gs.info("Task number is empty");
} else {
gs.info("Task number: " + task_number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 11:08 PM - edited 09-13-2023 11:10 PM
Hi @_navin9898
you mentioned that My assumption is that if file is empty, above code should return empty value/string. - If the file is empty then the onBefore script will not run,It executes at the start of a row transformation and before the row is transformed into the target row
You can use onStart which executes at the start of an import before any rows are read (The same code which you wrote will not work if onstart)
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
