how to create requests from the excel sheet that is attached to an inbound email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 09:38 AM
hi
how to create requests from the excel sheet data that is attached to an inbound email with particular subject?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 10:09 AM
HI there,
Set up an inbound email action: We'll create an inbound email action in ServiceNow that will process incoming emails. This action will be triggered when an email with the specific subject is received.
Parse the Excel sheet data: Within the inbound email action, we'll extract the attached Excel sheet and parse its data to gather the relevant information for creating the requests.
Create records in ServiceNow: Using the parsed data, we'll create new records in the appropriate table(s) in ServiceNow.
Here's an outline of the solution with some example code snippets:
Step 1: Create an inbound email action
// This script should be part of the inbound email action definition
function processInboundEmail(source, subject, body, attachments) {
// Check if the subject matches the specified subject
if (subject === "Request Data") {
// Call a function to process the Excel sheet data
processExcelData(attachments);
}
}
Step 2: Process the Excel sheet data
function processExcelData(attachments) {
// Assume the Excel sheet is the first attachment
var excelAttachment = attachments[0];
// Convert the Excel attachment to a JSON object or extract relevant data
var excelData = parseExcelToJSON(excelAttachment);
// Call a function to create records in ServiceNow based on the extracted data
createRecords(excelData);
}
Step 3: Create records in ServiceNow
function createRecords(excelData) {
// Assuming you have identified the target table for the records
var targetTable = "incident"; // Change this to the appropriate table name
// Loop through the parsed data and create records in ServiceNow
for (var i = 0; i < excelData.length; i++) {
var recordData = excelData[i];
// Create a new record in the target table
var newRecord = new GlideRecord(targetTable);
newRecord.initialize(); // Optional: Initializes a new record with default values
newRecord.setValue('short_description', recordData.short_description);
newRecord.setValue('description', recordData.description);
// Set other fields as needed based on your Excel data
// Insert the new record into the table
var sysID = newRecord.insert();
}
}
Regards,
Riya Verma