How do I create cases from incoming emails from external ones?

AndresGc
Tera Contributor

Hello team, I have a case of creating cases from emails from external people, from this point I know that there is an Inbound Email Actions called "Create case using prefix", but... is there a way to create a similar one with the same operation but that can allow anyone who sends an email to the instance account, using the same prefix, to generate cases.

 

I have created this inbound email action for external users but I can't get it to work

var subject_without_prefix = email.subject;
var subject = email.subject.split(gs.getProperty('glide.cs.email.new_case_prefix'));
if(subject.length > 1)
    subject_without_prefix = subject[1];

current.short_description = subject_without_prefix;
current.description = email.body_text;

var contact = new GlideRecord("customer_contact");
var contactID = new CSEMailUtil().getUserIDFromEmail(email.from); 

// Verificar si el correo es de un contacto interno o externo
if(contact.get(contactID)){
    var accountID = contact.account;
    var account = new GlideRecord("customer_account");
    if(account.get(accountID)){
        if(account.customer){
            current.contact = contact.sys_id;
            current.account = account.sys_id;
        }
    }
} else {
    // Manejar correos de personas externas con el mismo prefijo
    var externalContact = new GlideRecord("customer_contact");
    externalContact.addQuery("email", "STARTSWITH", gs.getProperty('glide.cs.email.new_case_prefix') + email.from);
    externalContact.query();
    if(externalContact.next()){
        current.contact = externalContact.sys_id;
        current.account = externalContact.account;
    }
}

current.contact_type = "email";
current.insert();


In the incoming email records you see the email information but it does not generate the case or relate it to the incoming email

AndresGc_0-1733893069334.png

 

In this case, as an example, I take the creation of an incident from the email, a function that comes by default in servicenow.

AndresGc_1-1733893201986.png

 

 

1 ACCEPTED SOLUTION

Antoni Zahariev
Tera Guru

There is an OOB [Create Case from Email] Flow in the Flow Designer where at the end of the [Create Case for matched or unmatched user] subflow there is a Case created for [Mail sent from unregistered user or multiple contacts/consumers correspond with the sent email].

 

Here is a link to the Flow:

https://<instance_name>.service-now.com/now/workflow-studio/builder?table=sys_hub_flow&sysId=877735290f0133008ca6dd1c5d767e9a 

 

Please, note that the flow might not be Active, nor Published.

 

In other words, if you Publish and Activate the suggested FLow there is no need for a custom Inbound Email Action to be created.

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@AndresGc 

so you are saying the same external user/email is able to create incident but not Case?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur
Taking it as an example, it would have to be that a user external to ServiceNow could generate a case simply by sending an email with the prefix *case:*, the screenshot below refers to the record that is linked as a demonstration that the case is created from that email.

Antoni Zahariev
Tera Guru

There is an OOB [Create Case from Email] Flow in the Flow Designer where at the end of the [Create Case for matched or unmatched user] subflow there is a Case created for [Mail sent from unregistered user or multiple contacts/consumers correspond with the sent email].

 

Here is a link to the Flow:

https://<instance_name>.service-now.com/now/workflow-studio/builder?table=sys_hub_flow&sysId=877735290f0133008ca6dd1c5d767e9a 

 

Please, note that the flow might not be Active, nor Published.

 

In other words, if you Publish and Activate the suggested FLow there is no need for a custom Inbound Email Action to be created.