Skip to content

Commit 151cca4

Browse files
script.js
1 parent fb13cf2 commit 151cca4

File tree

1 file changed

+41
-0
lines changed
  • Server-Side Components/Background Scripts/Delete Attachments - Closed Approvals

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
deleteinactiveattachments();
2+
3+
//deletes from approval table
4+
function deleteinactiveattachments() {
5+
var appr = new GlideRecord('sysapproval_approver');
6+
// appr.addQuery('sys_id','2d7f326287351ad0195eb99c8bbb35b5'); //uncomment this and replace sys_id and use this to check for 1 record
7+
appr.addEncodedQuery('state!=requested^ORstate=NULL');
8+
appr.query();
9+
while (appr.next()) {
10+
var answer = deleteparentattachment(appr.sys_id);
11+
deletechildattachment(appr.sys_id);
12+
if (answer == true || answer == 'true') {
13+
appr.comments = "Attachment's were removed from this record. If still needed it can be located at the corresponding ticket level.";
14+
appr.autoSysFields(false);
15+
appr.setWorkflow(false);
16+
appr.update();
17+
}
18+
}
19+
}
20+
//deletes from sys_attachment table
21+
function deleteparentattachment(record) {
22+
var attach_found = false;
23+
var attach_primary = new GlideRecord('sys_attachment');
24+
attach_primary.addQuery('table_sys_id', record);
25+
attach_primary.query();
26+
while (attach_primary.next()) {
27+
attach_primary.deleteRecord();
28+
attach_found = 'true';
29+
}
30+
return attach_found;
31+
}
32+
33+
//deletes from sys_attachment_doc table
34+
function deletechildattachment(record) {
35+
var attach_child = new GlideRecord('sys_attachment_doc');
36+
attach_child.addQuery('sys_attachment.table_sys_id', record);
37+
attach_child.query();
38+
while (attach_child.next()) {
39+
attach_child.deleteRecord();
40+
}
41+
}

0 commit comments

Comments
 (0)