
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2022 02:43 AM
SCENARIO:
A user submits a request from a catalog item, which results in a REQ record. While submitting the request, the user uploads an excel file, which contains the value to be parsed and populated into the RITM.
Note - Each row in the excel has to generate a new RITM.
Following has been my approach:
- Validate if the REQ submitted has attachments in the Condition field.
current.hasAttachments();
Excel Content-Type is application/vnd.ms-excel - how to validate? - Then the script to create the RITMs:
var grRITM = new GlideRecord("sc_req_item");
grRITM.initialize();
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attSysID = <NEED_HELP_TO_READ_ATTACHMENT_SYS_ID_FROM_REQUEST_SUBMITTED>;
var attachmentStream = attachment.getContentStream("attSysID");
parser.setSource(attachmentStream);
var list_sheet_name = parser.getSheetNames();
parser.setSheetName(list_sheet_name[i]);
var j = 0; //Row counter
var rowVal = []; //Array for fetching rowValues
// Parse each worksheet set using setSheetName()
if (parser.parse()) {
//retrieve the column headers, assuming excel has only 3 columnns.
var headers = parser.getColumnHeaders();
var h1 = headers[0];
var h2 = headers[1];
var h3 = headers[2];
// Iterate over each row in the worksheet
while (parser.next()) {
j++;
var row = parser.getRow();
rowVal[j].push(row[h1], row[h2], row[h3]);
}
} else
gs.info(parser.getErrorMessage());
// return rowVal;
}
Now, I want the RITM initialized to be saved with the description populating these extracted values from the excel.
grRITM.description =
"Input Label 1:"+rowVal[1].row[h1];
+"\nInput Label 2:"+rowVal[2].row[h2];
+"\nInput Label 3:"+rowVal[3].row[h3];
This is with the assumption that the values are in the excel in the below seen format:
Kindly suggest, where I have made a mistake and what better should I do to get this work?
Regards,
Anish
Solved! Go to Solution.
- 1,586 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2022 06:43 AM
It's done. https://code.jace.pro/?id=2022-05-08T12-04-05
Thanks Ankit for your help.
Cheers to all readers,
Anish
Slowly learning to Script in ServiceNow. 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 01:16 AM
Hey Vivi,
Thanks for highlighting, was a minor issue with the link, fixed it, please check and let me know.
Cheers,
Anish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2022 06:44 AM
Oh, that's great, I have opened it now, thank you so much for your fast answer, Anish!
Vivi Brasil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2022 12:59 AM
Cheers, no worries...
Wish you success with your piece of work, you are trying to achieve.
Best regards,
Anish