Skip to content

Commit 57782ff

Browse files
Feature/excel to mrvs populate (#2211)
* Create README.md Updating readme file with script functionality. * Create ParsingScript.js script to be used in script include * Update README.md Script working details
1 parent 599f55e commit 57782ff

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+

0 commit comments

Comments
 (0)