want to move 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-08-2023 04:42 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.
I have created a script include and catalog client script to achieve this functionality but it's not working. The alert(answer) is giving me null error.
Script include -
var labMRVS = Class.create();
labMRVS.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
var excelAttachment = this.getParameter('sysparm_id');
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(excelAttachment);
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
gs.log("Battery Test Lab logs: " + excelAttachment);
var partNumber = headers[0];
var groupName = headers[1];
var serialNumber = headers[2];
var swr = headers[3];
gs.log("Test Lab logs: " + srcip + " " + srchost + " " + tcp + " " + port);
while (parser.next()) {
var row = parser.getRow();
mrvs.push({
'part_number': row[srcip],
'group_name': row[srchost],
'traveler_serial_number': row[tcp],
'swr': row[port],
});
}
return JSON.stringify(mrvs);
},
});
On change Catalog client script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var attachment = g_form.getValue('attachments');
alert(attachment);
var ga2 = new GlideAjax('labMRVS');
ga2.addParam('sysparm_name', 'initialize');
ga2.addParam('sysparm_id', attachment);
ga2.getXML(processResponse);
function processResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('submit_multiple_requests_for_lab', answer);
alert(answer);
}
}
Thanks