Delete records on a custom table, when the record is deleted on the main table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 06:24 AM
Hello everyone!
I have a main table whith some records, and I have to create a new custom table to populate some records of the main.
This custom table has to be updated (When a record is inserted, updated or deleted).
I´ve just created a Business Rule with a SWITCH statement. (Is an AFTER business rule).
The BR is working for the Insert and for the update, but not for the DELETE.
If I delete a record on the main table, in the custom table appears like this:
I will share the code with you, to see if you can see what is wrong.
(function executeRule(current, previous /*null when async*/ ) {
var prevAppId = previous.getValue('u_application_id');
var prevGroup = previous.getValue('u_assigment_group');
var appId = current.getValue('u_application_id');
var appName = current.getUniqueValue();
var group = current.getValue('u_assigment_group');
var customTable = new GlideRecord('u_sn_app_air_ids');
customTable.addQuery('u_app_name', appName);
customTable.query();
switch (current.operation()) {
//--------------INSERT IS WORKING----------
case 'insert':
customTable.initialize();
customTable.u_air_id = appId;
customTable.u_app_name = appName;
customTable.u_group = group;
customTable.insert();
break;
//--------------UPDATE IS WORKING----------
case 'update':
//if (current.u_assignment_group.changes() || current.u_application_id.changes()) {
//customTable.addEncodedQuery('u_application_id=' + prevAppId + '^u_group.sys_id=' + prevGroup);
//customTable.query();
if (customTable.next()) {
customTable.u_air_id = appId;
customTable.u_app_name = appName;
customTable.u_group = group;
customTable.update();
}
// }
break;
//--------------DELETE IS NOT WORKING----------
case 'delete':
//customTable.addEncodedQuery('u_application_id=' + appId + '^u_group.sys_id=' + group);
//customTable.query();
if (customTable.next()) {
customTable.setWorkflow(false);
customTable.deleteRecord();
customTable.update();
}
break;
}
})(current, previous);
Thanks!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 07:54 AM
Yeap, I´ve just commented this line (I forgot to update the code before sharing).
But still have the same issue.