Inbound action script help for stripping only computer name

RudhraKAM
Tera Guru

Hello I need to create an Incident when an Email from xyz is being sent to servicenow , but email might have some computer names which I need to only get those names and set it in Description of Incident , 

Below is the email which we will get and we only want computer names under Problematic BCA clients . 

Thanks in advance 

 

RudhraKAM_0-1738174506132.png

 

 

6 REPLIES 6

JenniferRah
Mega Sage

Because the email is in HTML format, it's going to be tricky to parse out that information, especially if it's not always the same number of computers. If there's a way for them to change the way they send it to you so that it's in plain text and they can send it as a list, that would be easier to get. For example, if they can send it like this: 

Problematic BCA Client Computers: computername1, computername2

Then you could set the description like this: 

current.description = email.body.problematic_bca_client_computers;

there is no way we can change the email format 😞

Then I think the best you can do is dump the entire email message into an HTML field (maybe HTML Description?) or the work notes. That will be more information than they need, but it will at least include the information they need.

RudhraKAM
Tera Guru

they dont want full email too, i tried below script , still not working 

 

// Get the email body
var emailBody = email.body_html;  // or email.body_html if HTML email

// Define start and end markers for the section you want to extract
var startMarker = "Time Since";
var endMarker = "Snoozed BCA";

// Extract the content between markers
function extractSection(text, startMarker, endMarker) {
    var startIndex = text.indexOf(startMarker);
    var endIndex = text.indexOf(endMarker, startIndex);

    if (startIndex !== -1 && endIndex !== -1) {
        return text.substring(startIndex + startMarker.length, endIndex).trim();
    }
    return "Section not found";
}

// Call function to extract data
var extractedContent = extractSection(emailBody, "Time Since", "Snoozed BCA");

// Save extracted content to a field (e.g., incident short description)
current.work_notes = extractedContent;
//current.update();

// var emailBody = email.body_html.toString().replace(/<br\/>/g, "\n");
// current.description = emailBody;