Need help with attachment carry-over from one RITM to another

Hola Ola
Giga Guru

Hello all,

 

I have a request form that has attachment(s) that is/are required. 

 

At some point, when the RITM closes it automatically opens a new RITM.

 

I have a requirement to copy any/all attachment(s) from the closed RITM into the new RITM. 

 

Thank you

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Hola Ola You should use, 

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

Copies attachments from the source record to the target record.
 
Here is the sample source code.
 
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);

 

Please refer to this link for more information https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server_legacy/GlideSysAttachmentGl...

 

Hope this helps.

 

Jaspal Singh
Mega Patron
Mega Patron

Hi,

As Sandeep highlighted you can use GlideSysAttachment.copy() however it will consume the storage size over the period of time by unncessarily duplicating the attachments.

Instead you can follow a relationship approach to get the attachments presented as Related list instead. Check link for directions.