How to check I am reading from the right excel file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:59 AM - edited 09-20-2023 05:07 AM
Hi all,
I have a perculiar issue and am unsure how to solve it.
I am trying to parse through an excel docment and the code breaks at the line that uses getColumnHeaders as headers is 'null'.
How do I check if it is looking at the right excel document/why are the headers returning as null when there are definitely headers in the excel doc.
code in Script Include:
getAll: function() {
var excel = this.getParameter('sysparm_excelSheet');
//gs.addInfoMessage(excel);
var data = {
numCol: "",
numRow: "",
asset: "", };
data.numCol = this.verifyNumCol(excel);
//data.numRow = verifyNumRow(excel);
//data.asset = checkAssetTag(excel);
return JSON.stringify(data);
},
verifyNumCol: function(excel) {
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(excel);
var parser = new sn_impex.GlideExcelParser();
parser.parse(attachmentStream);
// //retrieve the column headers var headers = parser.getColumnHeaders();
gs.addInfoMessage('headers are ' + headers);
var headerOne = headers[0];
var headerTwo = headers[1];
var headerThree = headers[2];
gs.addInfoMessage('Header 1 is : ' + headerOne);
if ((headerOne.toString() == 'Asset Tag') && (headerTwo.toString() == 'Host Name') && (headerThree.toString() == '')) { return true; }
else { return false; } },
code in Catalog client script (OnSubmit):
var sys_id = g_form.getValue('sysparm_item_guid');
alert(sys_id);
var ga = new GlideAjax('AssignmentFour');
ga.addParam('sysparm_name', 'getAll');
ga.addParam('sysparm_excelSheet', sys_id);
ga.getXMLWait();
var result = ga.getAnswer();
var data = JSON.parse(result);
alert('Response is ' + result);
alert('numCol output is ' + data.numCol);
Any help would be much appreciated.
Kind regards,
G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 11:36 AM
Did you figure out why parser.getColumnHeaders() was null? I am getting the same and looking for hints 🙂