Send attachment data to external system using Rest API in JSON format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 07:50 AM
Hi Team,
I need to send attachment data to external system in JSON format. How can I do it?
Should I also encode data to base64 in this case?
Please help me!
Thank You
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2021 01:08 AM
You can then use Excel Parser to read the Excel file and send the data.
refer below link for example
Let me know if I have answered your question.
If so, 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2021 01:25 AM
Thank you for your quick response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2021 01:35 AM
Hi,
can you share how the JSON request should look like
Consider your excel has 4 rows and 4 columns so how it should be sent
Should it be sent row wise like this
{
"row1":"row1Data",
"row2":"row2Data",
"row3":"row3Data",
"row4":"row4Data"
}
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
06-01-2021 03:46 AM
Hi Ankur,
The excel contains dynamic rows and fixed columns.
The following code helps to read excel, please help me how can I convert the data to JSON in the following code.
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
gs.sleep(100);
if(gr.next()){//use `while` if dealing with multiple attachments
if(gr.getValue('file_name').indexOf('xlsm') != -1 && gr.getValue('file_name').indexOf('file1') != -1){
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// Use the attachment sys_id of an Excel file
var attachmentStream = attachment.getContentStream(gr.sys_id);
// Set the source to be parsed
parser.parse(attachmentStream);
// Get the worksheet names to be parsed in the Excel document
var list_sheet_name = parser.getSheetNames();
gs.info(" Sheet Names : " + list_sheet_name.join(", "));
//var headers = imp.getColumnHeaders().toString().split(',');
var headers = parser.getColumnHeaders();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2021 04:00 AM
Hi,
how the 3rd party expects the json request body?
you should ask them and include it accordingly
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader