- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2020 11:21 PM
In service now ,I can navigate to Rest API explorer and check the attachment API but we have to give table_name ,table_sys_id and file_name manually .Request body is binary
How to use the attachment API when we receive Inbound transaction (attachment ) Json as below
{
"number": "INC12345",
"tbl_name": "incident",
"att_payload" : "VGVzdCBhdHRhY2htZW50IGRhdGE=",
"att_name" : "Test.txt",
"att_cont_type" : "text/plain"
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2020 11:28 PM
Hi Kiran,
you can get the base64 encoded data by parsing the json response
then you can use GlideSysAttachment.write method to create attachment
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2020 11:28 PM
Hi Kiran,
you can get the base64 encoded data by parsing the json response
then you can use GlideSysAttachment.write method to create attachment
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2020 11:33 PM
Sample script below
I have hardcoded the json; but you will get the json response once you consume REST Endpoint
var json = '{"number":"INC12345","tbl_name":"incident","att_payload":"VGVzdCBhdHRhY2htZW50IGRhdGE=","att_name":"Test.txt","att_cont_type":"text/plain"}';
var parser = JSON.parse(json);
var base64String = parser.att_payload;
var tableName = parser.tbl_name;
var fileName = parser.att_name;
var contentType = parser.att_cont_type;
var number = parser.number;
var attachment = new GlideSysAttachment();
var gr = new GlideRecord(tableName);
gr.addQuery('number', number);
gr.query();
if(gr.next()){
var attachment_sys_id = attachment.writeBase64(gr, fileName, contentType, base64String );
gs.info("system attachment id:" + attachment_sys_id);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2020 03:14 AM
Glad to know that it helped.
If my response helped you please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader