Script Action not executing when triggered by custom event (mass update on custom table)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hey guys!
I’m implementing a feature that allows our superusers to enable restricted read access (
“Historical” simply means all existing records, regardless of state.
u_restricted_read_access = true) on historical tasks stored in a custom base table (x_vgll_rail_task).“Historical” simply means all existing records, regardless of state.
We already have functionality that removes restricted read access, and that part works fine using a GlideRecord loop directly in a Record Producer.
Now we want to enable restricted read access, but run the update asynchronously in the background, so that heavy mass-updates don’t block the user from doing other things in the platform.
To achieve this, I created:
- A custom event:
x_vgll_rail.add_restricted_access - A Script Action triggered by the event
- Updated logic in the Record Producer to:
- Count matching records
- Send the event if there are records to update
However, the Script Action never executes.
It seems the event is queued, but the Script Action does not run — I get no logs from inside it, and no records are updated.
I already have this old example script in the Record Producer which does what I will do, but the other way around:
It seems the event is queued, but the Script Action does not run — I get no logs from inside it, and no records are updated.
I already have this old example script in the Record Producer which does what I will do, but the other way around:
else if(action == 'remove_restricted_access') {
var taskGR = new GlideRecord('x_vgll_rail_task');
taskGR.addQuery('assignment_group', producer.assignment_group);
taskGR.addQuery('u_restricted_read_access', true);
taskGR.query();
while(taskGR.next()){
taskGR.u_restricted_read_access = false;
taskGR.setWorkflow(false);
taskGR.update();
}
gs.addInfoMessage('Begränsad läsåtkomst för historiska ärenden med utförargrupp ' + producer.name + ' är borttagen.');
current.setAbortAction(true);
producer.redirect = "x_vgll_rail_user_organisation_list.do";
}
This is the script in the record producer that I've added below the the example above:
else if (action == 'add_restricted_access') {
// 1. Hitta alla ärenden som ska påverkas
var taskGR2 = new GlideRecord('x_vgll_rail_task');
taskGR2.addQuery('assignment_group', producer.assignment_group);
taskGR2.addQuery('u_restricted_read_access', false); // inte redan begränsade
taskGR2.query();
var count = taskGR2.getRowCount();
if (count == 0) {
gs.addInfoMessage(
'Det finns inga historiska ärenden för utförargruppen ' +
producer.name +
' som kan få begränsad läsåtkomst.'
);
current.setAbortAction(true);
producer.redirect = 'x_vgll_rail_user_organisation_list.do';
} else {
// 2. Skicka ett event som Script Action tar hand om i bakgrunden
gs.eventQueue(
'x_vgll_rail.add_restricted_access', // event name
current, // current = record producer
producer.assignment_group, // parm1: sys_id på utförargruppen
producer.name // parm2: gruppens namn
);
// 3. Ge feedback till användaren
gs.addInfoMessage(
'Begränsad läsåtkomst kommer att läggas till för ' +
count +
' historiska ärenden med utförargrupp ' +
producer.name +
'. Processen körs i bakgrunden.'
);
current.setAbortAction(true);
producer.redirect = 'x_vgll_rail_user_organisation_list.do';
}
}
Here is the Script Action script:
(function executeAction(current, event) {
// 1. Hämta parametrar från eventet
var assignmentGroupSysId = event.parm1; // parm1: sys_id för assignment_group
var assignmentGroupName = event.parm2; // parm2: gruppens namn (för loggning)
// 2. Säkerhetskoll – om vi saknar assignment group, avbryt
if (!assignmentGroupSysId) {
gs.log(
'x_vgll_rail.add_restricted_access: Saknar assignment_group (parm1). Avbryter.',
'x_vgll_rail'
);
return;
}
// 3. Bygg GlideRecord mot bastabellen x_vgll_rail_task
var taskGR = new GlideRecord('x_vgll_rail_task');
// Filtrera på:
// - Assignment group (från eventet)
// - Bara de som INTE redan har begränsad läsåtkomst
taskGR.addQuery('assignment_group', assignmentGroupSysId);
taskGR.addQuery('u_restricted_read_access', false);
// 4. Kör query för att hitta matchande records
taskGR.query();
// 5. Räkna hur många ärenden vi hittade
var count = taskGR.getRowCount();
if (count === 0) {
// Inga records att uppdatera – logga bara
gs.log(
'x_vgll_rail.add_restricted_access: Inga ärenden att uppdatera för grupp: ' +
assignmentGroupName + ' (' + assignmentGroupSysId + ').',
'x_vgll_rail'
);
return;
}
// 6. Förbered massuppdatering
// Vi stänger av workflow och sys_fields för att spara prestanda
taskGR.setWorkflow(false);
taskGR.autoSysFields(false);
// 7. Sätt det fält som ska uppdateras
taskGR.setValue('u_restricted_read_access', true);
// 8. Kör massuppdatering i en enda DB-operation
taskGR.updateMultiple();
// 9. Logga resultatet
gs.log(
'x_vgll_rail.add_restricted_access: Satt u_restricted_read_access = true för ' +
count + ' ärenden med utförargrupp ' + assignmentGroupName +
' (' + assignmentGroupSysId + ').',
'x_vgll_rail'
);
})(current, event);Here comes a screenshot that shows the configuration for the event:
Here comes a screenshot for the configuration of the script action:
So what is could be the issue for why the code in the Script Action is not running? Can you see something I cannot?
Thanks in advance!