Skip to content

Commit c786bc5

Browse files
authored
BR to pass attachment from parent to child record (#2658)
* Create script.js * Create read.md
1 parent a2060e1 commit c786bc5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This script copies attachments from a source record in another table to the current record (likely a case or task).
2+
It ensures that attachments are preserved when creating or linking records across tables.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//This script copies attachments from a source record in another table to the current record (likely a case or task). It ensures that attachments are preserved when creating or linking records across tables.
2+
3+
4+
(function executeRule(current, previous /*null when async*/) {
5+
6+
if(!current.source_record || !current.source_table) {
7+
gs.info('No source record found for' + current.number);
8+
return;
9+
}
10+
var sourceId= current.source_record.toString();
11+
var sourceTable = current.source_table.toString();
12+
13+
gs.info('coping attachments from' + sourceTable + '[' + sourceId +'] case' + current.number);
14+
15+
try{
16+
var gsa = new GlideSysAttachment();
17+
var copiedCount = gsa.copy(sourceTable, sourceId, current.getTableName(), current.getUniqueValue());
18+
19+
20+
gs.info('Attachments copied from' + copiedCount +'attachment from' + sourceTable + ' to Case' + current.number);
21+
}catch (e) {
22+
gs.error('Attachment copied from case' +current.number + ': ' + e.message);
23+
}
24+
})(current, previous);

0 commit comments

Comments
 (0)