Need to inbound email action script for ticket creation

siva14
Tera Contributor

hello everyone,

 

we need help on inbound email script,

 

we have requirement that , whenever we received a mail from backup team, we need to look into their emails from last 2 hours , if we found the same attributes values repeats in their email body from last three emails, we need to create incident for the third email, attributes look like this , PFB screenshot, i have written the script to look in to email table but it's not working , anyone please help me that would be great help,

(note - Any one attribute value repeats in three emails also we can consider)

example, in the below screenshot , if location values repeats three times in the last three email, we need to consider to create incident

 

siva14_0-1740998397761.png

 

var senderEmail = email.from;
var emailBody = email.body_text.trim();
 
var emailCountGR = new GlideRecord('sys_email');
emailCountGR.addQuery('user_id', senderEmail).addOrCondition('user', senderEmail);
emailCountGR.addEncodedQuery('sys_created_on>=javascript:gs.beginningOfLast2Hours()');
emailCountGR.addQuery();
emailCountGR.addQuery('type', 'received');
emailCountGR.addQuery('receive_type', 'new');
emailCountGR.query();
while (emailCountGR.next()) {
var Locations = [];
var LocationPattern = /Location\s*:\s*(.+)/i;
   var body = emailCountGR.body.toString();
    var match = body.match(LocationPattern);
   
    }
}

 

 

 

#inbound #email #script 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@siva14 

I will suggest to use Flow as suggested by Mark.

in your existing script what debugging did you do?

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

@siva14 

you can use transform functions and get the value in flow and then store that in flow variable

the use lookup and check the count

How to parse email body text in flow designer inbound email? 

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