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 02:13 AM
this will help to give sleep in scoped app
var secondsValue = 5;
var seconds = parseInt(secondsValue, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
gs.info('Before time-> ' + new GlideDateTime().getValue());
while(start>parseInt(new Date().getTime())){
// do nothing
}
gs.info('After time->' + new GlideDateTime().getValue());
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 06:59 AM
should this be the script then?
var secondsValue = 5;
var seconds = parseInt(secondsValue, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
gs.info('Before time-> ' + new GlideDateTime().getValue());
while(start>parseInt(new Date().getTime())){
// do nothing
}
gs.info('After time->' + new GlideDateTime().getValue());
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);
}
As I tried this and this in not returning any info message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 07:03 AM
the script I shared for sleep should work fine in scoped app
why not use after update BR on table "sys_import_set_run"?
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 10:22 PM
Hi @Ankur Bawiskar ,
Actually i will not be able to write any script on "sys_import_set_run" as that is a global table. Can we do something in the transform script or the source/target table?
Regards,
Maharshi Chatterjee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 10:25 PM
then the delay logic I shared will work in scoped app
OR
you can use eventQueue based approach
a) trigger an event from onComplete transform script and use eventQueueScheduled() so that the event gets processed after 10 seconds, pass the import set sysId
b) associated script action with this event
c) then check the state in script action by querying the import set run table
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