- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2025 03:21 AM
I want my UI action script to run in background.
hey, I want to check record from list and then use the ui action to approver them (time cards)
the problem that im having that when I check couple of time cards and use the ui action it well take for ever to do the script.
can I run the process in the background ?
I will give the scripts
UI action :
form button - checked
list choice - checked
onClick - approveRecord();
script -
function approveRecord() {
var ga = new GlideAjax('global.ApproveScriptInclude');
ga.addParam('sysparm_name', 'approve');
var temp = g_list.getChecked();
ga.addParam('sysparm_record_id',temp);
ga.getXMLAnswer(handleResponse);
}
function handleResponse(response) {
//g_form.refresh();
}
and the script include
var ApproveScriptInclude = Class.create();
ApproveScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
approve: function() {
var recordIds = this.getParameter('sysparm_record_id').split(','); // Splitting the record IDs
var results = [];
recordIds.forEach(function(recordId) {
var gr = new GlideRecord('time_card'); // Specify the table name
if (gr.get(recordId.trim())) { // Trim spaces if any
try {
var isDataSeparationSkippedFromNowOnwards = typeof DataSeparatorGlobalUtil !== "undefined" ? DataSeparatorGlobalUtil.skipDataSeparation() : false;
gr.setValue('state', 'Approved');
var updateResult = gr.update();
if (updateResult) {
if (isDataSeparationSkippedFromNowOnwards) {
DataSeparatorGlobalUtil.honourDataSeparation();
}
results.push("success: " + recordId);
} else {
results.push("failure: could not update " + recordId);
}
} catch (e) {
results.push("failure: " + e + " in " + recordId);
}
} else {
results.push("failure: record not found " + recordId);
}
});
return JSON.stringify(results); // Returning JSON string of results for each record ID
},
type: 'ApproveScriptInclude'
});
I want the script to run in the background and not slow down my system
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2025 06:21 AM
Seems a duplicate question.
I already answered your other question which talks about the same requirement.
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-01-2025 06:21 AM
Seems a duplicate question.
I already answered your other question which talks about the same requirement.
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-02-2025 02:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2025 07:21 AM
Hi @eyal abu hamad ,
Please try below code in background script
new global.ApproveScriptInclude().approve()
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak