Copy value from excel to multi row variable set when attachment added in catalog item form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 01:06 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 01:44 AM
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);
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 02:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 06:37 AM
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