How to Copy Attachments from Case to Incident avoiding duplicates ?

Jay75
Tera Contributor

Hi everyone,

Can anyone guide me to copy attachments from 'Case' to 'Incident' without any duplicates ?

I have already tried this code which is working fine but I am getting duplicates everytime a new attachment is added.

please correct me how to avoid Duplicate attachments?

updateINCAttachment: function(source, sourceRecord) {

        var getIncident = new GlideRecord("sn_customerservice_case");

        getIncident.addQuery('sys_id', sourceRecord); // if i have case attachement with case sys id

        getIncident.query();

        if (getIncident.next()) {

            var IncidentsysId = getIncident.incident;

            //Updating the Incident attachment with Case attachment  

            GlideSysAttachment.copy('sn_customerservice_case', sourceRecord, 'incident', IncidentsysId);

        }

    },

 @Allen Andreas @Ankur Bawiskar 

1 ACCEPTED SOLUTION

Hi,

this link has solution which avoids loop

Copy Attachment from ritm to task and vice versa without looping

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

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Hi @ankur, Thanks for your response, your reply was very helpful but here is the scenario on which I am looking for a solution. I am copying attachments from CASE--> INC using "GlideSysAttachment.copy" in a BR. This is I was able to acheive. But my requirement is to sync attachment from both sides i.e., 'CASE-->INC' and 'INC-->CASE'. This is where problem starts if I try to write another BR on INC to copy attachments to CASE attachments are copied in a infinite loop on both ends. Please help me how to acheive 'Attachment sync between CASE and INC' without any duplicates from both directions. I will be greatful if you can help me on this. Thanks and regards Jay

Hi,

this link has solution which avoids loop

Copy Attachment from ritm to task and vice versa without looping

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

Regards
Ankur

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