- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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:
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
No, those files are not within the instance.
