GlidesysAttachment API is copying attachments every time when the record is inserted

aj2403
Tera Expert

Hi,

 

I am trying to copy the attachments from request to incident table. I know we can do it by "GlideSysAttachment.copy" method. But as per the functionality its copying repeatedly everytime. There is alternate way that we can try to delete all attachments and again we can copy those, but we should do in that way. I am trying to copy the latest attachment attached. Can anyone help on this. Because I searched the community, but unable to figure out this to attach only the latest attachment.

 

Thanks

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@aj2403 

you can just copy the latest file

check this link where solution is shared; enhance it as per your requirement

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

Hi Ankur,

 

Thanks for the reply. but that is not my requirement. the thing is when the user tries to attach any attachment in the request form, then that attachment has to insert in incident. we have relation between req and inc. 

for example:

REQ00001 - text1.txt file has been attached then that file has to attach to INC00001. With GlideSysAttachment.copy API is copying the attachments repeatedly. i tried by deleting the attachments in INC and again re-attaching from REQ which is working. But users will attach some files directly in INC which should not be deleted. the thing is we need to add whatever the user attach in REQ, that has to attach in INC without disturbing other attachments in INC. Thanks

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @aj2403 ,

 

Please check the response code from Ankur. It has approach to delete attachment first and then copy again.

Prevent duplicate attachments when copying 

 

If above is not helpful then check below article :-

Avoid duplicating attachment - GlideSysAttachment.copy() 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi Gunjan,

 

Thanks for the reply. but that is not my requirement. the thing is when the user tries to attach any attachment in the request form, then that attachment has to insert in incident. we have relation between req and inc. 

for example:

REQ00001 - text1.txt file has been attached then that file has to attach to INC00001. With GlideSysAttachment.copy API is copying the attachments repeatedly. i tried by deleting the attachments in INC and again re-attaching from REQ which is working. But users will attach some files directly in INC which should not be deleted. We need to add whatever the user attach in REQ, that has to attach in INC without disturbing other existing attachments in INC. Thanks