- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-07-2022 05:07 AM
Hello team,
Recently I was trying to archieve one requirement "copy attachments RITM level to TASK level and TASK level to RITM level without duplication. End your can see on portal what's happening on the task level". I tried to search answer on ServiceNow community but not get exact solution. After many trial Finally I found one solution we can do this using Business Rules.
You need you need to create 3 Business rules.
1) sc_task = copy RITM level to TASK level(before - insert)
2) sc_task = copy TASK level to RITM level(before - insert/update)
3) sys_attachment = remove duplicate attachments(before - insert, update)
1) sc_task = copy RITM level to TASK level(before - insert) :
script :
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('sys_attachment');
gr.addQuery("table_sys_id",current.sys_id);
gr.query();
GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);
gs.info(current.number);
})(current, previous);
2) sc_task = copy TASK level to RITM level(after - update):
script :
(function executeRule(current, previous /*null when async*/ ) {
GlideSysAttachment.copy('sc_task', current.sys_id, 'sc_req_item', current.request_item);
gs.info(current.number);
})(current, previous);
3) sys_attachment = remove duplicate attachments(before - insert, update) :
script :
(function executeRule(current, previous /*null when async*/ ) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', current.table_sys_id);
attach.addQuery('table_name', current.table_name);
attach.addQuery('file_name', current.file_name);
attach.addQuery('content_type', current.content_type);
attach.addQuery('size_bytes', current.size_bytes);
attach.query();
if (attach.next()) {
current.setAbortAction(true);
}
})(current, previous);
Hope this will solve your copy attachment issue.
If this works for you please feel free to mark Helpful
- 6,914 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
be cautious with copying attachments!
If you your company is at an enterprise level your attachment table will grow significantly, you can get performance issues and you will pay more money to ServiceNow as you consume more space in their data center.
There are other solutions available like a related list which contains links to the attachments of parent and child records.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
2) sys_attachment = remove duplicate attachments(before - insert, update) :
script :
(function executeRule(current, previous /*null when async*/ ) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', current.table_sys_id);
attach.addQuery('table_name', current.table_name);
attach.addQuery('file_name', current.file_name);
attach.addQuery('content_type', current.content_type);
attach.addQuery('size_bytes', current.size_bytes);
attach.query();
if (attach.next()) {
current.setAbortAction(true);
}
})(current, previous);