- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
I created a BR to duplicate the Task attachments for RITM, but the code doesn't work. Could you check what's happening with my script?
The rule is pointed to sc_task and is set to after, and execution is marked as insert and update.
(function executeRule(current, previous /*null when async*/ ) {
GlideSysAttachment.copy('sc_task', current.sys_id, 'sc_req_item', current.request_item);
gs.info('@@@anexo' + current.number);
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ideally you should have after insert BR on sys_attachment table so that whenever file is added on sc_task it gets copied to sc_req_item.
BR: After insert "sys_attachment"
Conditions: current.table_name == 'sc_task'
Script:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("sc_task");
gr.addQuery("sys_id", current.table_sys_id);
gr.query();
if (gr.next()) {
new GlideSysAttachment().copy("sc_task", gr.getUniqueValue(), 'sc_req_item', gr.request_item.toString());
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
You may need to include this line at the top of your code:
var attachment = new GlideSysAttachment();
And then change the existing .copy() line to this:
attachment.copy('sc_task', current.sys_id, 'sc_req_item', current.request_item);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Even making this adjustment didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ideally you should have after insert BR on sys_attachment table so that whenever file is added on sc_task it gets copied to sc_req_item.
BR: After insert "sys_attachment"
Conditions: current.table_name == 'sc_task'
Script:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord("sc_task");
gr.addQuery("sys_id", current.table_sys_id);
gr.query();
if (gr.next()) {
new GlideSysAttachment().copy("sc_task", gr.getUniqueValue(), 'sc_req_item', gr.request_item.toString());
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Another approach I will suggest is to show attachment related list on RITM.
This will avoid adding same file at 2 places and will save Attachment table size
check this link
TNT: "Related Attachments" Related List
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader