How-to Parse Excel Data into a MRVS?

John Shores1
ServiceNow Employee
ServiceNow Employee

Greetings, Community!

I have a use case where I need to allow a user to upload an Excel spreadsheet via a catalog item.  The spreadsheet could have more than 200 rows in it.  Once uploaded, the content of the file would be parsed into a MRVS (multi-row variable set) on the catalog item they imported the spreadsheet into and then submitted.

I've poked around the Internet a bit and haven't found anything close to this use case.

Anyone have any ideas how to go about doing this?

Thanks in advance for your thoughts! 

 

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

MRVS are stored in item_option_new_set table with type of "one_to_many",

 

find_real_file.png

Variables inside MRVS are stored in item_option_new table.

You can user OOB cart API to order catalog item and populate information from this spreadsheet into cart variables.

You will have to configure data source, transform map, scripts to call cart API.

 

https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/refer...

 

Regards,

Sachin

 

 

Regards,

Sachin

 

SatheeshKumar
Kilo Sage

I think you can create a button in form i.e  after attaching a attachment the user should click the button, so that we process in background and add fields to MRVS.

 

1. create a widget/macro button in form, configure button to call a script include on click of button

2. configure script include to parse the file for the current form and return the values in array of objects

 

script to parse file in server:

var parser = new sn_impex.GlideExcelParser(); 
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream(<attachment sys id>);

parser.parse(attachmentStream); 

//retrieve the column headers
var headers = parser.getColumnHeaders();  
var header1 = headers[0]; 
var header2 = headers[1]; 

//print headers
gs.print(header1 + " " + header2); 

while(parser.next()) { 
  var row = parser.getRow(); 
  //print row value for both columns   
  gs.print(row[header1] + ' ' + row[header2]) 
}

 

https://docs.servicenow.com/bundle/madrid-application-development/page/app-store/dev_portal/API_refe...

 

4. on receiving response set te mrvs with received values.

 

-satheesh

 

 

 

3. on getting response form 

Please write a example of how to call a script include when a button is clicked in a widget, as GlideAjax is not working in widgets

Gintarelissss98
Tera Contributor

how to get table_sys_id if attachment isn't yet submitted via widget script?