add template in inbound email action

dineshchall
Tera Contributor

Hi everyone,
I'm working on an Inbound Email Action that creates incidents. I want to apply a predefined Incident Template to populate default values like category, urgency, impact, assignment group, etc.

script:

    var incidentGr = new GlideRecord('incident');
    incidentGr.initialize();
    incident.applyTemplate('predefine_Template');
    incidentGr.caller_id = callerId;
    incidentGr.insert();
    incidentGr.work_notes = "Original email:\n" + body;
    incidentGr.update();

while script subject and caller field is populated from email. but from template it is not updated 
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@dineshchall 

what's there in template? share that screenshot.

what type of inbound action is this?

If that's type = New then you should use current object

var t = new GlideTemplate.get('template sysid');
t.apply(current);
current.work_notes = "Original email:\n" + body;
current.caller_id = callerId;
current.insert();

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

 

no OOB action
when i am using your script it creating two incidents one incident from email another incident from template 

dineshchall
Tera Contributor

while using this script incidents are created 2 i want to create only one incident in that incident i want to populated the email subject as short descrption and descrption populated through template.

dineshchall_0-1762181998827.png

dineshchall_1-1762182126184.pngdineshchall_2-1762182143471.pngdineshchall_3-1762182160945.png