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

@dineshchall 

there is already another OOTB New Type Inbound action on incident.

Is that deactivated?

Also in your new inbound action you should use current object and not GlideRecord and why to update it

Since you are using GlideRecord it's inserting 1 with current object and another with GlideRecord object

Please use current object, something like this please enhance

var userMatch = body.match(/Created \/ User\s *: \s*[\d\/\s]+\/\s*(\w+)/);
var callerId = userMatch ? userMatch[1] : '';

var t = new GlideTemplate.get('template sysid');
t.apply(current);
current.caller_id = callerId;
current.work_notes = "Original email:\n" + body;
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