logo

NJP

Copy Attachments RITM to TASK & Task to RITM without duplication

Import · Jul 07, 2022 · article

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

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/copy-attachments-ritm-to-task-task-to-ritm-without-duplication/ta-p/2302401