Split Email subject to update configuration item on Incident via Inbound Email Flow in Flow Designer

SanaPR
Giga Guru

Hi All,

Looking to create an Inbound Email Flow using Flow Designer, to create a new Incident whenever there is an email and ignore creation of incident if there is an outage already for this locationCI.
The email Subject is "Alerts for locationCI - Description".
I'm looking to split this email subject and update locationCI as Configuration Item and Location fields on Incident form.
Can someone explain me how to do it using inline script or any other way in Flow designer Inbound Email Flow.
My Trigger is Inbound email. Creating an Incident record with data from email user, subject etc.

Also can this Flow check if there is already any Outage for this locationCI running , then skip and donot create Incident. If no outages available then go ahead and create new incident. Can this also be achieved using Flow designer? Please help.

Thank you!

1 REPLY 1

ShreyasK0030
Kilo Guru

 

Step 1: Creating the Inbound Email Flow

  1. Navigate to Flow Designer:

    • Go to Flow Designer in ServiceNow.
  2. Create a New Flow:

    • Click on New to create a new flow.
    • Name your flow, for instance "Create Incident from Email".
  3. Add a Trigger:

    • Select Inbound Email as the trigger.
    • Configure the trigger to run when an email is received.

Step 2: Extraction of information from the email subject

  1. Add an Action to Split the Email Subject:
    • Add a new action and select script step.
    • Use the following script to split the email subject and extract location CI and description :
(function execute(inputs, outputs)
{
  var subject = inputs.email.subject;
  var parts = subject.split(" - ");
  if (parts.length === 2)
{
  outputs.locationCI = parts[0].replace("Alerts for ", "").trim();
  outputs.description = parts[1].trim();
}
else
{
  outputs.locationCI = "";
  outputs.description = subject;
}
})(inputs, outputs);
 2. Define Inputs and Outputs:
  • Define inputs.email.subject as the input.
  • Define outputs.locationCI and outputs.description as the outputs.

Step 3: Check for Existing Outages

  1. Add a Condition to Check for Existing Outages:

    • Add a new action of look up records.
    • Configure it to look up records in the incident table where:
      • configuration item matches locationCI value.
      • state is in progress or any other state that indicates an outage.
    • Store the result in a variable, for instance existingOutage.
  2. Add a Condition to Check if Outage Exists:

    • Add an if condition to check if existingOutage value is not empty.
    • If it is not empty, add an action to end the flow.

Step 4: Create a New Incident

  1. Add an Action to Create an Incident:
    • Add a new action to create a record
    • Configure it to create a new record in the incident table.
    • Map the fields as follows:
      • Short Description to inputs.email.subject
      • description to outputs.description.
      • Configuration Item to outputs.locationCI.
      • location to outputs.location (or map it to the appropriate location field).

Step 5: Save and Activate the Flow

  1. Save the Flow:

    • Click on Save to save your flow.
  2. Activate the Flow:

    • Click on Activate to activate your flow.