how to create requests from the excel sheet that is attached to an inbound email

Rahul Raja Sami
Tera Guru

hi 

how to create requests from the excel sheet data that is attached to an inbound email with particular subject?

 

 

1 REPLY 1

Riya Verma
Kilo Sage
Kilo Sage

HI there,

  1. 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.

  2. 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.

  3. 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();
    }
}

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma