How to copy data from attachment to the multi row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 05:59 AM
Hello Community,
We have a requirement where, upon adding an attachment, the data should be populated in the Multi-Row Variable Set. Can anyone provide guidance on how to achieve this?
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:23 AM
Hi @hema sundar ,
The GlideExcelParser API in ServiceNow is used for parsing Excel files and extracting data from them. Here is one example of how you can extract data from an excel. This might help you:
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', 'your_table_name');
grAttachment.addQuery('table_sys_id', 'your_record_sys_id');
grAttachment.query();
if (grAttachment.next()) {
var attachmentSysId = grAttachment.sys_id;
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(attachmentSysId);
var excelParser = new GlideExcelParser();
excelParser.parse(attachmentStream);
while (excelParser.next()) {
var row = excelParser.getRow();
var column1 = row.getCell(0).getValue(); // Get value of first column
var column2 = row.getCell(1).getValue(); // Get value of second column
// Process the extracted values
}
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera