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

Onkar Pandav
Tera Guru

Hi,

Please check with below changes.

if (email.subject.indexOf(toLowerCase("machine"))) >= 0

{

   //your code

}

Check and let me know.

sri83
Tera Guru

Still, same error is getting and incident is not created.

Please help me on the same

premer
Giga Expert

Is this an inbound rule in the global scope or a scoped application?

Mohit Kaushik
Mega Sage
Mega Sage

Hi Sri,

You can do this in the conditions module itself instead of writing the script.

find_real_file.png

Moreover please check the action type of inbound action also, is it record action or reply email.

find_real_file.png

apart from this check if the type is New or forward or reply.

find_real_file.png

 

 

Please mark this answer correct if it resolved the query and mark it helpful too if it helped you at all.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)