Parse Excel to JSON format
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I am trying to read an attachment file from a attachment variable to parse data in it and build a JSON payload per row with header as name and value as key to use that information on a variable. to make any progress , I cant get past the parser.parse line, not seeing any error too. testing below script in a fix script and then use it it in a client callable script include
var jsonData = [];
var attachmentSysId = '12f78a92938407509f98fa252603d6d6';
gs.info('AttachmentSysId--->' + attachmentSysId);
// Uses sn_impex namespace to parse attachment stream
var parser = new sn_impex.GlideExcelParser();
var attachmentStream = new GlideSysAttachment().getContentStream(attachmentSysId);
gs.info('AttachmentStream--->' + attachmentStream);
if (attachmentStream) {
gs.info('AttachmentStreamExists');
parser.parse(attachmentStream); //Data exists in the excel file and it has only 1 sheet and 1 row in that sheet exluding header
while (parser.next()) {
// Collects row data into the JSON array
gs.info('ParserExists');
jsonData.push(parser.getRow());
}
}
gs.info(JSON.stringify(jsonData));
Output:
*** Script: AttachmentSysId--->12f78a92938407509f98fa252603d6d6
*** Script: AttachmentStream--->com.glide.communications.GlideScriptableInputStream@74f0306d
*** Script: AttachmentStreamExists
*** Script: []
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @monikagmk12 ,
Your script is working . I tested with a xl sheet . Just want to verify from which file type are you trying to extract the data?
If it is .csv it won't work.
