Shamma Negi
Kilo Sage

Hi All,

 

We have a class which helps us to copy the attachment from one record to another record in ServiceNow. Please have a look:

 

GlideSysAttachment()

Creates an instance of the GlideSysAttachment class.
 

copy(String sourceTable, String sourceID, String targetTable, String targetID)

Copies attachments from the source record to the target record.
 
Here is an example of the above statement:
 

Example

 

 

var attachment = new GlideSysAttachment();
var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
var incGR = new GlideRecord('incident');
incGR.get(incidentSysID);

var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
gs.info('Copied attachments: ' + copiedAttachments);
 

Output

 

Copied attachments: 6e4621df1bc420501363ff37dc4bcbb0,a87769531b0820501363ff37dc4bcba2

 

Hope this helps.

I hope this article helpful. Please mark it as helpful and bookmark if you like it.

 

Regards,

Shamma Negi