Transform script for Throwing error if there is error while importing records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:40 AM
Hi,
I have a staging table ,transform map and target table. Now I am reading the excel and with a br I am creating records in the staging table and with the transform map I am creating records in the target table. Now I want to show the user an alert whatever is the status of the transformation like if it is completed/completed with errors. So I have written an oncomplete transform script but here the status is showing as running instead of the actual status. What changes do i need to do in the script or do I need to change the approach of the alert?
var transformrec = new GlideRecord('sys_import_set_run');
transformrec.addQuery('set', source.sys_import_set);
transformrec.query();
if (transformrec.next()) {
gs.info('state'+transformrec.state);
gs.info('test22' + transformrec.sys_id);
gs.info('req'+source.request_number);
}
Ideally the status should show completed with errors but it is showing as running.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:45 AM
What if you write the script onAfter?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:58 AM
Hi Mark,
Thanks for you reply.
Onafter is actually printing the same result for all the records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 01:48 AM
it's because the onComplete transform script runs immediately when last row is processed but the import set run might not be completed by that time
Couple of ways to handle this
1) add some delay in your transform script
OR
2) check for completion in loop
OR
3) event based approach
a) create event and fire it from BR on import set run
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
12-16-2024 02:04 AM
Hi Ankur,
Thanks for your reply.
This is a scoped app so will sleep work for delay or is there any other way to add the delay.