Copy attachments from one SCTask to antoher

Kishor Mudhili
Giga Guru

hi Guys,

 

how we can copy attachments from one SC Tasks to another SCTasks.

 

for example: one request having multiple SCTasks, I 'm not going attach the attachments in Request.

I want to attach the attachment in any SCTAsk, that attachment should be copied to antoher tasks..

please help me. 

17 REPLIES 17

jaheerhattiwale
Mega Sage

@Kishor Mudhili Wrie a business rule on sys_attachment table

jaheerhattiwale_0-1672655005008.png

 

Add below code in business rule

 

(function executeRule(current, previous /*null when async*/ ) {

var currentScTask = new GlideRecord("sc_task");
if (currentScTask.get(current.table_sys_id.toString())) {
var catTask = new GlideRecord("sc_task");
catTask.addQuery("sys_id!=" + current.table_sys_id.toString());
catTask.addQuery("request=" + currentScTask.request.toString());
catTask.query();

while (catTask.next()) {
GlideSysAttachment().copy("sc_task", currentScTask.sys_id.toString(), "sc_task", catTask.sys_id.toString());
}
}

})(current, previous);

 

Please mark as correct answer if this solves your issue.

hello Jaheer,

 

how did you get this ?, wihout this i have wrintten the code on SCTask table but not working

KishorMudhili_0-1672660129285.png

 

@Kishor Mudhili you need to add business rule on sys_attachment table not on sc_task.

 

Please create it and check.

 

Please mark as correct answer if this solves your issue 

@Kishor Mudhili I have updated the code.

 

Create after insert business rule on sys_attachment table and below code

 

(function executeRule(current, previous /*null when async*/ ) {

var currentScTask = new GlideRecord("sc_task");
if (currentScTask.get(current.table_sys_id.toString())) {
var catTask = new GlideRecord("sc_task");
catTask.addQuery("sys_id!=" + current.table_sys_id.toString());
catTask.addQuery("request=" + currentScTask.request.toString());
catTask.query();

while (catTask.next()) {
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name=sc_task");
attachment.addQuery("table_sys_id="+catTask.sys_id.toString());
attachment.addQuery("file_name="+current.file_name.toString());
attachment.query();

if(!attachment.hasNext()){
GlideSysAttachment().copy("sc_task", currentScTask.sys_id.toString(), "sc_task", catTask.sys_id.toString());
}
}
}

})(current, previous);
 
Please mark as correct answer if this solves your issue.

Won't this just run in loop if you have more than one sc_task?