diff --git a/Server-Side Components/Script Includes/Populate MRVS from Excel/ParsingScript.js b/Server-Side Components/Script Includes/Populate MRVS from Excel/ParsingScript.js new file mode 100644 index 0000000000..871e3747e9 --- /dev/null +++ b/Server-Side Components/Script Includes/Populate MRVS from Excel/ParsingScript.js @@ -0,0 +1,20 @@ +parseExcel: function() { + var attachSysId = this.getParameter('sysparm_id'); + var attachment = new GlideSysAttachment(); + var parser = new sn_impex.GlideExcelParser(); + var mrvsArray = []; + // get content of the attachment + var content = attachment.getContentStream(attachSysId); + parser.parse(content); + // Iterate through each row after header. Return false if row doesn't exist + while (parser.next()) { + // get content of the row + var row = parser.getRow(); + //push the object with key same as variable name in the MRVS. + var obj = {}; + obj.employee_id = row['Id']; + obj.employee_name = row['Name']; + mrvsArray.push(obj); + } + return JSON.stringify(mrvsArray); +}, diff --git a/Server-Side Components/Script Includes/Populate MRVS from Excel/README.md b/Server-Side Components/Script Includes/Populate MRVS from Excel/README.md new file mode 100644 index 0000000000..614e5a6b26 --- /dev/null +++ b/Server-Side Components/Script Includes/Populate MRVS from Excel/README.md @@ -0,0 +1,16 @@ +This script allows to parse the excel file attached to the attachment variable and populate the MRVS present in the +catalog item / record producer. +Use this script in a client-callable script include along with an onChange client script on the attachment variable. + +When a file is uploaded as an attachment, it's metdata is stored in the sys_attachment table and sys_attachment_doc contains +the actual binary content. + +**getContentStream()** converts the binary content in a way so that it can be parsed by GlideExcelParser API. + +**Example used-** + +The excel has two columns "Id" and "Name" to store employee details. MRVS also has the variable name as "employee_id" and "employee_name". + + + +