Attach Excel to catalog item to populate values in a Multi Row Variable Set (MRVs)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 01:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 05:20 AM
Yeah, do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 05:50 AM
Hi Brad ,
How we can achieve this in portal for MRVS for 13 columns>
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2022 11:18 AM
Here is a script I use in a UI Action in the native UI so that end users with only the itil role can populate an empty MRVS with data from an Excel spreadsheet on an RITM or Catalog Task. If you want to do this in the Service Portal, do you mean on the request form or on a record after the request is submitted? I could see some challenges with doing this before the request is submitted, so it might be best to have the requestor attach the Excel, then submit the request, then your workflow or a Business Rule could populate the MRVS.
This example takes the most-recently attached Excel file (or there's a line commented out where you can hard-code the name) and imports the data into a MRVS. In this example the Excel file contains 3 columns and the first row is headers. I'm not doing any validation as this wasn't necessary in this case, but the first column in Excel is a model display name and the variable in the MRVS is a reference type, so I'm looking up the sys_id.
current.update();
action.setRedirectURL(current);
var att = new GlideRecord('sys_attachment');
//att.addQuery('file_name', 'serial number import.xlsx');
att.addQuery('content_type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
att.addQuery('table_sys_id', current.sys_id);
att.orderByDesc('sys_created_on');
att.query();
if(att.next()){
var imp = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(att.sys_id.toString());
imp.parse(attachmentStream);
var headers = imp.getColumnHeaders();
var model = headers[0];
var snt = headers[1];
var sn = headers[2];
var count = 0;
var newRow = '';
while(imp.next()) {
var row = imp.getRow();
var mrvs = current.variables.network_gear_asset_mrvs; //MRVS internal name
newRow = mrvs.addRow();
var mdl = new GlideRecord('cmdb_model');
mdl.addQuery('display_name', row[model]);
mdl.query();
if(mdl.next()){
newRow.v_mrvs_model = mdl.sys_id;
}
newRow.v_mrvs_serial_number_temp = row[snt];
newRow.v_mrvs_serial_number = row[sn];
count++;
}
if(count > 0){
gs.addInfoMessage(count + ' rows added to Network Gear Assets table.');
}
current.update();
action.setRedirectURL(current);
}