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

@suuriyas 

log clearly says condition not satisfied

Did you keep that updated condition and check by adding logs in script include?

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

Shruti
Mega Sage
Mega Sage

Condition - new global.KAL_Inbound_Actions().validSender(email.origemail)

 

Script include 

var KAL_Inbound_Actions = Class.create();
KAL_Inbound_Actions.prototype = {
    initialize: function() {},
    validSender: function(emailId) {
        var validEmail = false;
        var allowedDomains = gs.getProperty("itsm.email").toLowerCase().split(',');
       
        for (var j = 0; j < allowedDomains.length; j++) {
            var domain = allowedDomains[j].trim();
           
            if (emailId.endsWith("@" + domain)) {
                validEmail = true;
                break;
            }
        }


        return validEmail;
    },
    type: 'KAL_Inbound_Actions'
};