How to copy data from attachment to the multi row variable set

hema sundar
Tera Contributor

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,

hemasundar_0-1716296139279.png

 

1 REPLY 1

Amitoj Wadhera
Kilo Sage

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