Map the RITM attachment data to the alm_hardware table and insert the records from the attachment ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have created an inbound email action flow to create the RITM and copy the attachment from the email to the RITM. The attachment is successfully coming to the RITM. Now, the attachment headers should be mapped to the ALM Hardware table, and the Excel data should also be inserted into the ALM Hardware table using a script in ServiceNow.
Below I have mentioned the business rule script .
(function executeRule(current, previous) {
try {
gs.info("Business Rule Started");
gs.info("Short Description: " + current.short_description);
// Check based on email subject
if (current.short_description == "To create this catalog for Dell shipment asset Mapping purpose") {
gs.info("Inbound Email RITM Identified");
// Get attachment from RITM
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.query();
if (!attachmentGR.hasNext()) {
gs.info("No Attachment Found");
}
while (attachmentGR.next()) {
gs.info("Attachment Found: " + attachmentGR.file_name);
// Parse Excel
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var stream = attachment.getContentStream(attachmentGR.sys_id);
parser.parse(stream);
// Print headers
var headers = parser.getColumnHeaders();
gs.info("Excel Headers: " + headers);
// Read rows
while (parser.next()) {
gs.info("Reading Excel Row");
var alm = new GlideRecord('alm_hardware');
alm.initialize();
// Mapping
alm.mac_address = parser.getValue('Mac Address');
alm.po_number = parser.getValue('PO Number');
alm.serial_number = parser.getValue('Service Tag');
// Reference fields may require sys_id
alm.model = parser.getValue('Model');
alm.manufacturer = parser.getValue('Manufacturer');
var sysId = alm.insert();
gs.info("Inserted Record Sys ID: " + sysId);
}
}
}
} catch (ex) {
gs.error("Error in Business Rule: " + ex);
}
})(current, previous);
The above script troughing the error
please help me on this.
Thanks,
karishma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
15m ago
Hey @karishmas749252
(function executeRule(current, previous) {
if (current.short_description == "To create this catalog for Dell shipment asset Mapping purpose") {
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'sc_req_item');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.query();
while (attachmentGR.next()) {
var parser = new sn_impex.GlideExcelParser();
var attachmentSys = new GlideSysAttachment();
var inputStream = attachmentSys.getContentStream(attachmentGR.sys_id);
parser.setSource(inputStream);
if (parser.parse()) {
while (parser.next()) {
var alm = new GlideRecord('alm_hardware');
alm.initialize();
alm.mac_address = parser.getValue('Mac Address');
alm.serial_number = parser.getValue('Service Tag');
alm.insert();
}
} else {
gs.error("Parse error: " + parser.getErrorMessage());
}
}
}
})(current, previous);
