Abort the scheduled data import through Pre-script script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 06:52 AM
I need to abort the scheduled data import from Excel, based on checking headers of imported Excel sheet.
From Below script I'm able to get the headers name in system logs but cannot find a funtion which I can call inside the if(header1 != 'Allocation Logic') to abort the import submission.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 09:37 AM
Hi @Sagar Pagar ,
PFB SS and Code aswell.
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id",'f7ed9ac61b84555041abdb12f54bcb76');
gr.query();
if (gr.next()) {
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(gr.sys_id.toString());
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
// gs.addInfoMessage("ca" +headers.toString());
var header1 = headers[0];
// gs.info("headers from sheet" + headers.toString());
// gs.info("headers from sheet header1" + header1);
if(header1 == 'Allocation Logic'){
gs.info("headers from sheet header2" + header1);
cancel = true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 12:17 PM
Have you tried placing the variable containing the decision on the very last line (to be executed)?
E.g:
var cancel = false;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_sys_id", 'f7ed9ac61b84555041abdb12f54bcb76');
gr.query();
if (gr.next()) {
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(gr.sys_id.toString());
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
// gs.addInfoMessage("ca" +headers.toString());
var header1 = headers[0];
// gs.info("headers from sheet" + headers.toString());
// gs.info("headers from sheet header1" + header1);
if (header1 == 'Allocation Logic') {
gs.info("headers from sheet header2" + header1);
cancel = true;
}
}
!cancel;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 12:22 PM
Chuch T. says this is mentioned somewhere in the docs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 06:14 AM
Hi @-O- This is still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 06:47 AM
check my latest response
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
