How to attach some file in format excel or PDF on many Asset with a load file or other solution

mathieucoss
Tera Contributor

In ServiceNow Asset table we have many file to attach on many Asset Entry. We don't want to do it manually. Do we have a solution to do all attachement in 'one shot'

1 REPLY 1

Najmuddin Mohd
Mega Sage

Hello @mathieucoss ,
You can check out the out of the box function.

copy(String sourceTable, String sourceID, String targetTable, String targetID)
Copies attachments from the source record to the target record.


First attach a file to one record. 
GlideRecord the records to which it should be attached, and write a for loop and add this copy function in it.


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);

 


https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server_legacy/GlideSysAttachmentGloba...

 

 

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.