File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Server-Side Components/Script Includes/Populate MRVS from Excel Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ parseExcel : function ( ) {
2+ var attachSysId = this . getParameter ( 'sysparm_id' ) ;
3+ var attachment = new GlideSysAttachment ( ) ;
4+ var parser = new sn_impex . GlideExcelParser ( ) ;
5+ var mrvsArray = [ ] ;
6+ // get content of the attachment
7+ var content = attachment . getContentStream ( attachSysId ) ;
8+ parser . parse ( content ) ;
9+ // Iterate through each row after header. Return false if row doesn't exist
10+ while ( parser . next ( ) ) {
11+ // get content of the row
12+ var row = parser . getRow ( ) ;
13+ //push the object with key same as variable name in the MRVS.
14+ var obj = { } ;
15+ obj . employee_id = row [ 'Id' ] ;
16+ obj . employee_name = row [ 'Name' ] ;
17+ mrvsArray . push ( obj ) ;
18+ }
19+ return JSON . stringify ( mrvsArray ) ;
20+ } ,
Original file line number Diff line number Diff line change 1+ This script allows to parse the excel file attached to the attachment variable and populate the MRVS present in the
2+ catalog item / record producer.
3+ Use this script in a client-callable script include along with an onChange client script on the attachment variable.
4+
5+ When a file is uploaded as an attachment, it's metdata is stored in the sys_attachment table and sys_attachment_doc contains
6+ the actual binary content.
7+
8+ ** getContentStream()** converts the binary content in a way so that it can be parsed by GlideExcelParser API.
9+
10+ ** Example used-**
11+
12+ The excel has two columns "Id" and "Name" to store employee details. MRVS also has the variable name as "employee_id" and "employee_name".
13+
14+
15+
16+
You can’t perform that action at this time.
0 commit comments