particular domain mail id needs to create an incident

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, only particular domains mail id need to create an incident. we have an inbound email action created in an incident table.

Inbound email action condition : new global.KAL_Inbound_Actions().validSender(email.recipients.toLowerCase())||email.recipients.indexOf(gs.getProperty('instance_name')+'@service-now.com') > -1

 

Script include:

var KAL_Inbound_Actions = Class.create();
KAL_Inbound_Actions.prototype = Object.extendsObject(AbstractAjaxProcessor, {

validSender: function(recepients) {
        var validEmail = false;
        var itsmEmails = gs.getProperty("itsm.email").toLowerCase().split(',');
        for(var i=0; i<itsmEmails.length; i++)
            {
                if(validEmail==true)
                {
                    break;
                }
                else
                {
                    if(recepients.indexOf(itsmEmails[i])>-1)
                    {
                        validEmail=true;
                        //gs.log('xxxRavs '+itsmEmails[i]);
                    }
                }
               
            }
        return validEmail;
    },

    type: 'KAL_Inbound_Actions'
});
itsm.email is a property where we have mentioned 2 comma separated emails. example x@gmail.com, x@yahoo.com
So now only sender with that mail id only satisfy the inbound condition and incident will be created.
But now my requirement is any mail id with that domain needs to create an incident.
for example xyx@gmail.com yena@yahoo.com like this any mail id with domain @gmail.com and @yahoo.com can able to create an incident
 
How can i achieve this?
Thanks in advance
6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

try this

1) update property as this -> gmail.com,yahoo.com

2) update script include as this

var KAL_Inbound_Actions = Class.create();
KAL_Inbound_Actions.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    validSender: function(recipients) {
        var validEmail = false;
        var allowedDomains = gs.getProperty("itsm.email").toLowerCase().split(',');
        // Extract sender email from recipients (assuming recipients is a string of emails)
        var recipientList = recipients.split(',');
        for (var i = 0; i < recipientList.length; i++) {
            var email = recipientList[i].trim();
            for (var j = 0; j < allowedDomains.length; j++) {
                var domain = allowedDomains[j].trim();
                // Check if email ends with @domain
                if (email.endsWith("@" + domain)) {
                    validEmail = true;
                    break;
                }
            }
            if (validEmail) break;
        }
        return validEmail;
    },

    type: 'KAL_Inbound_Actions'
});

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

HI @Ankur Bawiskar ,

 

Thanks for the response 

I tried this but it did not work.

Created a new system property (with values as mentioned)  and update that property in script include like your.

And i tried sending an mail from my mail id (i have that domain name in my mail id) but it did not work...incident not created 

@suuriyas 

did you debug and see what came in logs?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

HI @Ankur Bawiskar ,

 

Yes, 

Actual inbound condition : new global.KAL_Inbound_Actions().validSender(email.recipients.toLowerCase())||email.recipients.indexOf(gs.getProperty('instance_name')+'@service-now.com') > -1

 

so i removed ||email.recipients.indexOf(gs.getProperty('instance_name')+'@service-now.com') > -1 and tested why because with this part incident is getting created even with the old script when i sent mail from my mail id to dev instances mail id. incident is getting created so i removed it and  tested.

this is the log i recieved

(Skipping script 'KAL_Create Incident - New', condition 'new global.KAL_Inbound_Actions().validSender(email.recipients.toLowerCase())' failed)