The CreatorCon Call for Content is officially open! Get started here.

Need to understand the condition

suuriyas
Tera Contributor

HI Community,

 

Can you please enlighten me what exactly is mentioned here:

This is the condition for inbound email action to create an incident 

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

 

in this i can see KAL_Inbound_Actions in script include and validSender is function but i don't understand the rest

 

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 the property that mentioned in script so only the emails mentioned in that property value can able to create an incident is it right?
1 ACCEPTED SOLUTION

@suuriyas 

Condition:

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

 

1. global.KAL_Inbound_Actions().validSender(email.recipients.toLowerCase()) -> This will check if the sender emai id is part of the email list or not. Here we are passing the sender email to the script include function.

 

2. email.recipients.indexOf(gs.getProperty('instance_name')+'@service-now.com') > -1 -> This will chcek if the sender email id is matching with the intance email id. Here we are fetching the instanace id from the system property gs.getProperty('instance_name').

If either Condition 1 or Condition 2 is satisfied, the email will be processed; otherwise, it will be skipped.

 

View solution in original post

4 REPLIES 4

J Siva
Kilo Patron
Kilo Patron

Hi @suuriyas 
I believe comma-separated email IDs are stored in the system property itsm.email. The system checks whether the sender's email ID is included in the list stored in this property. If it is, the script returns true.
Regards,
Siva

suuriyas
Tera Contributor

HI @J Siva ,

 

Thanks for the response

Yes in property we have comma-separated email IDs are stored. yes script returns true but can you please explain the condition mentioned in inbound action.

 

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

 

im not getting it

@suuriyas 

var itsmEmails = gs.getProperty("itsm.email").toLowerCase().split(',');: This line retrieves a property named itsm.email using the gs.getProperty method (likely a ServiceNow global object function) and converts it to lowercase. It then splits the string into an array of email addresses using the comma as a delimiter.

for(var i=0; i<itsmEmails.length; i++): A for loop is initiated to iterate over each email in the itsmEmails array.

Inside the loop, the code checks if validEmail is true. If it is, the loop breaks early, meaning a valid email has already been found.

If validEmail is false, it checks if the current itsmEmails[i] is present in the recepients string using recepients.indexOf(itsmEmails[i]) > -1. The indexOf method returns the position of the first occurrence of a specified value within a string, or -1 if it is not found.

If the email is found in recepients, validEmail is set to true, indicating a valid email was found. The commented-out line //gs.log('xxxRavs '+itsmEmails[i]); suggests that there might have been a logging statement for debugging purposes.

@suuriyas 

Condition:

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

 

1. global.KAL_Inbound_Actions().validSender(email.recipients.toLowerCase()) -> This will check if the sender emai id is part of the email list or not. Here we are passing the sender email to the script include function.

 

2. email.recipients.indexOf(gs.getProperty('instance_name')+'@service-now.com') > -1 -> This will chcek if the sender email id is matching with the intance email id. Here we are fetching the instanace id from the system property gs.getProperty('instance_name').

If either Condition 1 or Condition 2 is satisfied, the email will be processed; otherwise, it will be skipped.