Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto-create Customer Contact from Inbound Email – Inbound Action Not Triggering

swethavelu
Tera Contributor

Hi Community,


I’m trying to auto-create a Customer Contact record when an inbound email is received. Here’s what I did:

  • Created an Inbound Email Action in Global scope.
  • Action Type: Record Action, Target Table: customer_contact.
  • Execution Order: 10, Weight: 100.
  • No conditions (to allow all emails).
  • Script checks if contact exists, then creates a new record with email, name, company (from subject), and phone (from body).
  • Tested the script in Script Background – it works and creates the contact.
  • Email account is configured and emails appear under System Logs → Emails → Received.
  • But the inbound action never fires. I noticed the received emails have Type = received, while my inbound action was set to Type = None.

Question:

  • Is the Type field causing this issue?
  • Are there any other settings required for inbound actions to trigger?
  • If inbound actions are unreliable, what’s the best alternative to achieve auto-contact creation?

Fyi, below is the script action.

(function runAction(current, event, email, logger, classifier) {

    gs.log('Inbound Email Action triggered for: ' + email.from);

    // Check if contact already exists
    var existing = new GlideRecord('customer_contact');
    existing.addQuery('email', email.from);
    existing.query();

    if (!existing.next()) {
        var contact = new GlideRecord('customer_contact');
        contact.initialize();

        // Extract name from display name or email prefix
        var nameParts = [];
        if (email.origFromName) {
            nameParts = email.origFromName.split(' ');
        } else {
            var emailPrefix = email.from.split('@')[0];
            nameParts = [emailPrefix];
        }

        contact.first_name = nameParts[0];
        contact.last_name = nameParts.length > 1 ? nameParts[1] : '';
        contact.email = email.from;

        // Parse company from subject
        var companyMatch = email.subject.match(/Company:\s*([A-Za-z0-9\s]+)/);
        if (companyMatch) {
            contact.company = companyMatch[1].trim();
        }

        // Parse phone from body
        var phoneMatch = email.body_text.match(/Phone:\s*([\+\d\-]+)/);
        if (phoneMatch) {
            contact.phone = phoneMatch[1].trim();
        }

        contact.insert();
        gs.log('New Customer Contact created for ' + email.from);
    } else {
        gs.log('Contact already exists for ' + email.from);
    }

})(current, event, email, logger, classifier);
 

Any guidance or best practices would be appreciated!

 

Thanks & regards,

swetha.

9 REPLIES 9

Anil Nemmikanti
Tera Guru
Tera Guru

Yes, I believe. Please select "Type" as New and try. Thanks.

Hi @Anil Nemmikanti 

 

Thanks for your response, when i changed the type to "New" seeing below message in log.
Skipping script 'Create Customer Contact from Email', email is a reply, and the record it matches is not in the Inbound Email Action's table

Looks like the customer is replying on the provided email.
If this is the case, then the Type = Reply.

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0535515

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG 

 

No, whenever servicenow receives inbound emails from any customer and if the customer contact does not exist wants to create new contact record for them.