Want to copy the attachments from parent to child case

saic2
Tera Contributor

I want to know that if we have 5 attachments in parent case and I need an ability to select and copy only 2 out of 5 attachments into child case. Is It possible? 

6 REPLIES 6

Abbas_5
Tera Sage
Tera Sage

Hello @saic2,

 

Yes,  You can write a After BR insert/ update

(function executeRule(current, previous){
var parentRecord = new GlideRecord('parent_table');

parentRecord.addQuery('sys_id', current.parent_id);

parentRecord.query();

 

if(parentRecord.next()){

var attach = new GlidesysAttachment();

var attachments copied = attach.copy('parent_table',parentRecord.sys_id,current.getTableName(),current.sys_id);

if(attachments copied < 2){

gs.info('copied' + attachments copied + 'attachments from ' + parentRecord.sys_id + 'to' + current.sys_id);

}) (current, previous);

 

If it is helpful, please hit the thumbs up button and accept the correct the solution by referring to this solution in future it will be helpful to them.

 

Thanks & Regards,

Abbas Shaik

@Abbas_5 

Seems you misunderstood the question.

The question says to copy 2 out of 5 files and not all.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@saic2 

if you use GlideSysAttachment.copy() it will copy all

To copy specific you need custom logic, check below link and enhance, I shared solution 6 years ago

Is there any way to copy single attachment from multiple attachments ?? 

also check this link

How to copy attachment from one File attachment field to another table 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@saic2 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader