- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 04:18 AM
I have the below UI action-client(scoped) and script include(scoped), When I test with high load, the script is getting transaction cancelled with "maximum execution time exceeded". How can I get this script executed so that its not timed out. Is it possible to run a run scheduled script on click of ui action and how? Please help with script.
script include:
var AttachmentParserScoped = Class.create();
AttachmentParserScoped.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getExcelInfo: function() {
var currentSysId = this.getParameter('sysparm_sys_id');
var currentParent = this.getParameter('sysparm_parent');
var attachment = new GlideSysAttachment();
var getdata = new GlideRecord('sys_attachment');
getdata.addQuery('table_sys_id', currentSysId);
getdata.addQuery('table_name', "x_fdrbl_task");
getdata.query();
if (getdata.next()) {
//An attachment is found
var attachmentSysID = getdata.sys_id.toString();
var attachmentStream = attachment.getContentStream(attachmentSysID);
var demodata = new sn_impex.GlideExcelParser();
demodata.parse(attachmentStream);
var caseID = [];
var resolvedBy = [];
var headers = demodata.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
while (demodata.next()) {
var row = demodata.getRow();
caseID.push(row[header1]);
resolvedBy.push(row[header2]);
}
var finalArr = [];
finalArr[0] = caseID.toString();
finalArr[1] = resolvedBy.toString();
// ***** Create entries in x_fdrbl_quality_control_list table******//
for (var i = 0; i < caseID.length; i++) {
var qualityControlList = new GlideRecord('x_fdrbl_quality_control');
qualityControlList.initialize();
qualityControlList.parent_id = currentSysId;
// Check if the username exists in sys_user table
var userName = resolvedBy[i];
var userDetail = new GlideRecord('sys_user');
userDetail.addQuery('name', userName);
userDetail.addQuery('email', 'CONTAINS', '@uion.com');
userDetail.query();
if (userDetail.next()) {
qualityControlList.resolved_by = userDetail.sys_id.toString();
qualityControlList.subteam = userDetail.u_sub_team;
qualityControlList.parentteam = userDetail.u_parent_team;
} else {
gs.addErrorMessage("Resolved by user not found: " + userName);
}
qualityControlList.case_id = caseID[i];
qualityControlList.insert();
// var attachmentDlt = new GlideSysAttachment();
// attachmentDlt.deleteAttachment(attachmentSysID);
}
} else {
gs.addErrorMessage("Please attach a file to import the data");
}
},
type: 'AttachmentParserScoped'
});
/// ui action:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 05:36 AM - edited 01-17-2025 05:45 AM
No UI action required.
Simply do this
1) use async insert/update BR and call that script include inside it
BR: Condition: After update (With correct import_state condition)
(function executeRule(current, previous /*null when async*/) {
// Add your code here
new AttachmentParserScoped().getExcelInfo(current.getUniqueValue());
})(current, previous);
Script Include:
var AttachmentParserScoped = Class.create();
AttachmentParserScoped.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getExcelInfo: function(sysId) {
var currentSysId = sysId;
var attachment = new GlideSysAttachment();
var getdata = new GlideRecord('sys_attachment');
getdata.addQuery('table_sys_id', currentSysId);
getdata.addQuery('table_name', "x_fdrbl_task");
getdata.query();
if (getdata.next()) {
//An attachment is found
var attachmentSysID = getdata.sys_id.toString();
var attachmentStream = attachment.getContentStream(attachmentSysID);
var demodata = new sn_impex.GlideExcelParser();
demodata.parse(attachmentStream);
var caseID = [];
var resolvedBy = [];
var headers = demodata.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
while (demodata.next()) {
var row = demodata.getRow();
caseID.push(row[header1]);
resolvedBy.push(row[header2]);
}
var finalArr = [];
finalArr[0] = caseID.toString();
finalArr[1] = resolvedBy.toString();
// ***** Create entries in x_fdrbl_quality_control_list table******//
for (var i = 0; i < caseID.length; i++) {
var qualityControlList = new GlideRecord('x_fdrbl_quality_control');
qualityControlList.initialize();
qualityControlList.parent_id = currentSysId;
// Check if the username exists in sys_user table
var userName = resolvedBy[i];
var userDetail = new GlideRecord('sys_user');
userDetail.addQuery('name', userName);
userDetail.addQuery('email', 'CONTAINS', '@uion.com');
userDetail.query();
if (userDetail.next()) {
qualityControlList.resolved_by = userDetail.sys_id.toString();
qualityControlList.subteam = userDetail.u_sub_team;
qualityControlList.parentteam = userDetail.u_parent_team;
} else {
gs.addErrorMessage("Resolved by user not found: " + userName);
}
qualityControlList.case_id = caseID[i];
qualityControlList.insert();
// var attachmentDlt = new GlideSysAttachment();
// attachmentDlt.deleteAttachment(attachmentSysID);
var gr = new GlideRecord("x_fdrbl_task");
gr.addQuery("sys_id", currentSysId);
gr.query();
if (gr.next()) {
gr.import_state = 'Complete';
gr.update();
}
}
} else {
gs.addErrorMessage("Please attach a file to import the data");
}
},
type: 'AttachmentParserScoped'
});
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
01-17-2025 04:45 AM
something like this, but please enhance
Auto load Excel spreadsheet using Email Inbound Action
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
01-17-2025 04:58 AM
@Ankur Bawiskar Is it possible to make this script include call asynchronous?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 05:03 AM
try this
function showDetails() {
g_form.setVisible('import_state', true);
g_form.setValue('import_state', 'In progress');
alert("Please wait import is in progress" );
var systemId = g_form.getUniqueValue();
var ga = new GlideAjax('AttachmentParserScoped');
ga.addParam('sysparm_name', 'getExcelInfo');
ga.addParam('sysparm_sys_id', systemId);
ga.getXMLAnswer();
}
g_form.setVisible('import_state', false);
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
01-17-2025 05:26 AM
@Ankur Bawiskar It is working the same way.. will an asyn BR help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 05:28 AM
yes you can use async BR
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