Stop creating incident through email if more records found

siva14
Tera Contributor

Hi All,

 

We have a requirement that, update incident create inbound action to search for email from this sender received in the last 4 hours with target table of incident. if more then 20 found, do not create record and do not allow to continue processing other inbound actions

How can I achieve this one.

Any help would be appreciated. Thanks in Advance.

 

#inbound #script include

9 REPLIES 9

Hi @siva14 ,

In that case let's try using current.setAbortAction(true) in the if condition and remove the below statements :

stopProcessing = true;
event.state = 'stop_processing';
 
Please try it and let me know if this fixed the problem.
 

Please mark this answer as "helpful" and mark it as "correct" If you feel this helped you in anyway.

 

Thanks and Regards,

K. Sai Charan

Sr. ServiceNow Developer 

Deloitte India 

Hi @Sai_Charan_K 

 

Now i am facing another issue

 

the 4 hour part of the query was not working so i updated it with a new encoded query but the user_id != email.origemail.
email.origemail returns the email which user_id is looking for a sys_id.

 

i also, updated that user_id query to look for the specific sys_id of my tests but the processing did not stop and an INC was created.

Hi @slimgam ,

Can you please provide the script which you used?

 

Thanks and Regards,

K. Sai Charan

Hi @Sai_Charan_K 

PFB script

 

var senderEmail = email.origemail;
gs.log(email.origemail, "Inbound Email Action:  Create Incident");

var emailCountGR = new GlideRecord('sys_email');
emailCountGR.addQuery('user_id', 'f1ad308cdb218fc0536c776baf9619a8');//senderEmail);
emailCountGR.addEncodedQuery('sys_created_onRELATIVEGT@hour@ago@4');
emailCountGR.addQuery('target_table', 'incident');
emailCountGR.addQuery('type','received');
emailCountGR.addQuery('receive_type', 'new');
emailCountGR.query();

if (emailCountGR.getRowCount() > 20) {
    gs.log("More than 20 emails received from sender: " + senderEmail + " in the last 4 hours. Skipping incident creation.", "Inbound Email Action:  Create Incident");
    current.setAbortAction(true);

  }

siva14
Tera Contributor

Hi @Sai_Charan_K , Any update on this, "email.origemail" is not working, is there any other query we can use for that, Any help would be appreciated.