How to use email.subject.startsWith("test1") method in the inbound action?

sri83
Tera Guru

Hi Team,

I am creating the incident through inbound action when email received to system with subject start with "machine"

Email is receiving to system but ticket is not creating and it's showing the error as "did not create or update incident using current"

Script:

var subj = email.subject.toLowerCase();
var subj1 = subj.startsWith("machine");
if (subj1 == true || subj1 == 'true') {
current.u_requestor = 'f5425ad92bde620048dd60ec17da1556';
current.caller_id = 'f5425ad92bde620048dd60ec17da1556';
current.description = email.body_text;
current.short_description = email.subject;
var sub = email.subject;
current.category = " Reporting";
current.subcategory = "Data";
current.incident_state = 10;
current.state = 10;
current.contact_type = "email";
current.assignment_group = '5db01aa413b52e008fda37f1f244b'; 
current.insert();
}

6 REPLIES 6

Hi Mohit,

Thanks for shared the screenshot.

We are getting multiple subjects based on the subject we are creating the incident with category,subcategory's.

So please help me how to hard code the subject lines in the script.

 

Regards,

Sri

Hi Sri,

I have tested the below script in my personal instance and it is working completely fine.

if(email.subject.toString().startsWith('machine')) //you can filter it with startsWith condition, just remember this that it is case sensitive.
{
current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description=email.subject;
current.insert();
gs.log("It is my incident rule which has run");
}

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)