We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Uploading attachment through transform Map

Aaviii
Tera Contributor

Hi,

 

I have a requirement to upload data through excel which contains column of attachment links. I want these attachments to be attached to the records inserted or updated.

1 ACCEPTED SOLUTION

@Aaviii 

then this sample script in your onAfter transform script should work fine

I tested with this sample external URL and file got attached to incident record

So you can enhance it so that it picks target sysId using target.sys_id

var url = 'https://s24.q4cdn.com/216390268/files/doc_downloads/test.pdf'; // your download URL
var targetTable = 'incident'; // record table
var targetSysId = '79f8565afbb936100db5f8454eefdc40'; // record sys_id

var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('GET');
request.setEndpoint(url);
// This creates sys_attachment + sys_attachment_doc on the fly
var attachmentSysId = request.saveResponseBodyAsAttachment(targetTable, targetSysId, 'downloaded_file'); // name without extension
var response = request.execute();

var httpResponseStatus = response.getStatusCode();
gs.debug("http response status_code: " + httpResponseStatus);

Output:

download and attach file from external system to target record.gif

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

@Aaviii 

Sorry but you didn't inform in your original question that you are in scoped app

You should have shared complete details in original post itself

The script I shared did work for me when I ran it in scoped app in background script

Couple of cross scope were created and allowed

AnkurBawiskar_0-1766977836017.png

 

AnkurBawiskar_1-1766977878992.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Alok Gupta5
Tera Guru

Hi @Aaviii ,

 

Can you please tell if these attachments are already present in the serviceNow 'sys_attachment' table?

 

if Yes , Then the logic mentioned by Matthew will work otherwise first you have upload all the attachment in the attachment table. then you have to use the below code mentioned by @Matthew_13.

 

 

Please mark as Accepted Solution and Thumbs Up if you find Helpful!!

 


 

 

 

Regards,

Alok Gupta

Technical Architect

No, those files are not within the instance.