Copy value from excel to multi row variable set when attachment added in catalog item form

Siddharth4
Tera Contributor

Hi,

 

I have created a MRVS having 4 rows and an attachment button in a catalog Item form in a portal. I have a requirement that when user added an attachment then all the value will be copied to the MRVS.

We have a standard excel template which we will upload in the attachment variable. The excel sheet will have multiple columns and rows and we want the value of these rows to be copied to the MRVS just after the attachment get submitted in Item form from portal.

Kindly suggest and provide the steps or script to achieve this functionality. 

 

Thanks 

3 REPLIES 3

BharathChintala
Mega Sage

@Siddharth4 

try below 

This would be in a Client callable Script Include called from GlideAjax in the Client Script, passing in newValue.  The Excel file should have column headers on row 1.

var mrvs = [];
var json = new JSON();
var attid = this.getParameter('sysparm_attachment'); //newValue passed in from Client Script
var imp = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(attid);
imp.parse(attachmentStream);
var headers = imp.getColumnHeaders();
var srcip = headers[0];
var srchost = headers[1]; 
var tcp = headers[2];
var port = headers[3];
var destip = headers[4];
var desthost = headers[5];
while(imp.next()) {
    var row = imp.getRow();
    mrvs.push({
        'source_ip_or_subnet' : row[srcip],
        'source_hostname_or_description' : row[srchost],
        'tcp_udp' : row[tcp],
        'service_port' : row[port],
        'destination_ip_or_subnet' : row[destip],
        'destination_hostname_or_description' : row[desthost]
    });
}
return json.encode(mrvs);

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Hi @BharathChintala,

 

The script you provided is the script include one, can you please help me with catalog client script as well to call the GlideAjax.

 

Thanks

Hi @BharathChintala,

 

The script you provided is the script include one, can you please help me with catalog client script as well to call the GlideAjax.

 

Thanks