Inbound email action from a specific domain rather than user

Nabilah
Tera Contributor

 

I need some guidance on creating an inbound email action with the following criteria:

  • When an email is received from the domain: @Example.com

  • With an email subject starting with: SN-APP-INC

It should create an Incident with these values:

  • Assignment Group: Business Information

  • Requester: 1st line of the email body

  • Channel: Self-Service

  • Service: BI

  • Incident status: Assigned

  • Priority: P5 - 5 working days

  • System: 3rd line of the email body

  • Resolution Service: BI

  • Short Description: [the email subject]

  • Description: [the email body]

The emails will be generated by an application in the following format (examples below). These are forwarded to ServiceNow, and the inbound action should raise the incident accordingly.

Example 1

From: John Doe
Sent: 09 May 2025 12:43
To: John Doe <John.Doe@example.com>
Subject: SN-APP-INC: EMP-MSC-PBI-001 – Employee Account Changes - John.Doe@example.com

 

JDoe1
EMP-MSC-PBI-001 – Employee Account Changes
Power BI Non Live
BI-CUS-TMP - Temporary Report Store - PUBLISHED
Power BI

 

Example 2

 

From: John Doe
Sent: 09 May 2025 13:41
To: John Doe <John.Doe@example.com>
Subject: SN-APP-INC: Target Test H2PWYNI - John.Doe@example.com

 

JDoe1
Target Test H2PWYNI
Microsoft Power BI
BI-CUS-TMP - Temporary Report Store - PUBLISHED
Power BI

 

 

How would i go about doing this??

11 REPLIES 11

Hi @Nabilah,

1. Using Headers

The Headers field contains the raw email header information, which always includes the "From" address. This is the most reliable way to check the sender's domain.

  • Select Headers from the dropdown menu.

  • Set the condition as Headers contains From: <your_domain_here>.

2. Using Body Text

This is a less reliable method but may work if the email template includes the sender's email address in the body.

  • Select Body text from the dropdown menu.

  • Set the condition as Body text contains @example.co.uk.

3. Alternative: A More Reliable Method

If you're still having trouble, the best practice is to set the condition to To contains <your_inbound_email_address> and then use a script in the inbound action to check the sender's domain. This method is more robust and allows for more complex validation.

Hi @M Iftikhar , there is no option to pick "From" or "Email From" in the conditions. 

@M Iftikhar thank you it has now worked and generated an incident by looking at the headers. However it has not populated the requestor or system on the incident form. Is there something wrong with my business rule script?

Nabilah_0-1757603295149.png

 

Hi @Nabilah ,

The issue with the requestor and system not populating is likely due to the script not correctly parsing the information from the email headers. To help you troubleshoot, could you please share the script from your Business Rule?

If my response helps, please mark it as the accepted solution so others can benefit as well. Thanks!

 

(function runAction(current, email, action, event) {

    var body = email.body_text || email.body || '';
    var lines = body.split(/\r?\n/).map(function(s) {
        return s.trim();
    }).filter(Boolean);

    // -------------------
    // Requester from line 1
    // -------------------
    var requesterToken = lines[0] || '';
    if (requesterToken) {
        var u = new GlideRecord('sys_user');
        if (requesterToken.indexOf('@') > -1) {
            u.addQuery('email', requesterToken);
        } else {
            u.addQuery('user_name', requesterToken);
        }
        u.setLimit(1);
        u.query();
        if (u.next()) {
            current.caller_id = u.sys_id;
        }
    }

    // -------------------
    // System from line 3
    // -------------------
    var systemValue = lines[2] || '';
    if (systemValue && current.isValidField('u_system')) {
        current.category = systemValue; 
    }

})(current, email, action, event);