Skip to content

Commit 91a03d2

Browse files
Create Script.js
1 parent 3d1ff94 commit 91a03d2

File tree

1 file changed

+18
-0
lines changed
  • Server-Side Components/Business Rules/Move attachment from variable to record

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// Find attachments linked to variables (table_sys_id of RITM's variables)
4+
var attGR = new GlideRecord('sys_attachment');
5+
attGR.addQuery('table_sys_id', current.sys_id); // attachment originally linked to variable of this RITM
6+
attGR.addQuery('table_name', '!=', 'sc_req_item'); // exclude already moved attachments
7+
attGR.query();
8+
9+
while (attGR.next()) {
10+
gs.info('Moving attachment: ' + attGR.file_name);
11+
12+
// Update to associate with the RITM record
13+
attGR.table_name = 'sc_req_item';
14+
attGR.table_sys_id = current.sys_id;
15+
attGR.update();
16+
}
17+
18+
})(current, previous);

0 commit comments

Comments
 (0)