We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to fetch attachment from one table and populate that attachment to another table custom field

s_105
Tera Contributor

Hi All, I have a requirement to fetch the attachment from one table and stored/ autopopulate that attachment to custom field in servicenow. This custom field should autopopulate the attachment from table.

Thank you!

3 REPLIES 3

Sandeep Rajput
Tera Patron

@s_105 What type of custom field you are referring here? 

 

OOTB you can use GlideSysAttachment - copy(String sourceTable, String sourceID, String targetTable, String targetID)

 

Here is an 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);

 

For more information, please refer to https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/G....

Hi @Sandeep Rajput ,

I am able to copy it at table level, but my requirement is to copy that attachment to field not to table.

@s_105 Could you please state your end goal here? Why would you like to copy the attachment at field level?