- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:12 PM
Hello,
I'm using the following script to parse an Excel file:
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream('61d8600297262110610dbfb6f053af1c');
parser.parse(attachmentStream);
//retrieve the column headers
var headers = parser.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
//print headers
gs.info(header1 + " " + header2);
while(parser.next()) {
var row = parser.getRow();
//print row value for both columns
gs.info(row[header1] + ' ' + row[header2])
}
The output including "Null" values:
I just want to print the row with values. Can someone help please?
Thank you
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:26 PM
@Lisa Goldman Please try the following script.
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream('61d8600297262110610dbfb6f053af1c');
parser.parse(attachmentStream);
//retrieve the column headers
var headers = parser.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
//print headers
if (header1 && header2) {
gs.info(header1 + " " + header2);
}
while (parser.next()) {
var row = parser.getRow();
//print row value for both columns
if (row[header1] && row[header2]) {
gs.info(row[header1] + ' ' + row[header2]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:48 PM
try to check if value is not null
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream('61d8600297262110610dbfb6f053af1c');
parser.parse(attachmentStream);
//retrieve the column headers
var headers = parser.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
//print headers
gs.info(header1 + " " + header2);
while(parser.next()) {
var row = parser.getRow();
//print row value for both columns
if(row[header1] != null && row[header2] != null)
gs.info(row[header1] + ' ' + row[header2]);
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:26 PM
@Lisa Goldman Please try the following script.
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream('61d8600297262110610dbfb6f053af1c');
parser.parse(attachmentStream);
//retrieve the column headers
var headers = parser.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
//print headers
if (header1 && header2) {
gs.info(header1 + " " + header2);
}
while (parser.next()) {
var row = parser.getRow();
//print row value for both columns
if (row[header1] && row[header2]) {
gs.info(row[header1] + ' ' + row[header2]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 08:48 PM
try to check if value is not null
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream('61d8600297262110610dbfb6f053af1c');
parser.parse(attachmentStream);
//retrieve the column headers
var headers = parser.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
//print headers
gs.info(header1 + " " + header2);
while(parser.next()) {
var row = parser.getRow();
//print row value for both columns
if(row[header1] != null && row[header2] != null)
gs.info(row[header1] + ' ' + row[header2]);
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 12:13 AM
If your using array then use this :-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 10:13 PM
HI @Lisa Goldman ,
I trust you are doing great.
Looking at your current script, you are already pa
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
// use attachment sys id of an excel file
var attachmentStream = attachment.getContentStream('61d8600297262110610dbfb6f053af1c');
parser.parse(attachmentStream);
while(parser.next()) {
var row = parser.getRow();
//print row values for both columns
gs.info(row[0] + ' ' + row[1]);
}
rsing the Excel file using the GlideExcelParser() function and retrieving the column headers using the getColumnHeaders() function. To print the row values, you simply need to modify the while loop to print the row variable instead of the headers. Here's an updated script:
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi