inbound email action to update the incident assignment group based on the subject line

Mansi roy
Tera Contributor

Hi All,


Can anyone please help me on the below requirement.

 

The incident should be created automatically when the email will come to the mail id..and based on the subject the assignment group should be set automatically.

 

Please let me know how to achieve this.

 

Regards,

Mansi

14 REPLIES 14

Mansi roy
Tera Contributor

Hello @Anoja,

Thank you for the response. i need to auto assign the incident based on subject line.Suppose the email contains servicenow it will get auto assign to servicenow group.likethis i have more than 25 or 30 groups.How to achieve that one.

Community Alums
Not applicable

Hi Mansi,

 

Could you please try this way 

 

// Initialize the email subject

var subject = email.subject.toLowerCase(); // Create a GlideRecord object for the Subject Group Mapping table

var mapping = new GlideRecord('u_subject_group_mapping'); // Replace with your table name mapping.addQuery('u_keyword', 'LIKE', subject); // Ensure your keyword field is indexed for performance mapping.query(); // Initialize assignment group

var assignmentGroup = null; // Check if we have a matching record

if (mapping.next()) {

assignmentGroup = mapping.u_assignment_group; // Replace with your group field name

} // If a mapping was found, assign the incident to the group

if (assignmentGroup) {

var incident = new GlideRecord('incident');

if (incident.get(email.reference)) {

incident.assignment_group = assignmentGroup;

incident.update();

}

} else {

gs.info ('No assignment group found for the subject: ' + subject);

}

 

Thanks!

Community Alums
Not applicable

Hi Mansi,

 

Could you please try this way 

 

// Initialize the email subject

var subject = email.subject.toLowerCase(); // Create a GlideRecord object for the Subject Group Mapping table

var mapping = new GlideRecord('u_subject_group_mapping'); // Replace with your table name mapping.addQuery('u_keyword', 'LIKE', subject); // Ensure your keyword field is indexed for performance mapping.query(); // Initialize assignment group

var assignmentGroup = null; // Check if we have a matching record

if (mapping.next()) {

assignmentGroup = mapping.u_assignment_group; // Replace with your group field name

} // If a mapping was found, assign the incident to the group

if (assignmentGroup) {

var incident = new GlideRecord('incident');

if (incident.get(email.reference)) {

incident.assignment_group = assignmentGroup;

incident.update();

}

} else {

gs.info ('No assignment group found for the subject: ' + subject);

}

 

Thanks!

Hello @Community Alums,

 

Shall i update on the email action.

Hello @Community Alums , @Dr Atul G- LNG ,

 

I have created one table with name support group and i have created two columns one is assignment group and another one is subject.

 

I have updated the below code in inbound action. The  incident is getting created.

 

But i am not getting why the assignment group is not taking from the table. Could please anyone help on  this.

 

the below is the code for inbound action.  

 

//  Note: current.opened_by is already set to the first UserID that matches the From: email address

current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;

current.category = "Hardware";
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";

if (email.body.assign != undefined)
   current.assigned_to = email.body.assign;

if (email.importance != undefined) {
   if (email.importance.toLowerCase() == "high") {
        current.impact = 1;
        current.urgency = 1;
   }
}

   var subject = email.subject.toLowerCase(); // Create a GlideRecord object for the Subject Group Mapping table

var mapping = new GlideRecord('u_subject_group_mapping'); // Replace with your table name mapping.addQuery('u_keyword', 'LIKE', subject); // Ensure your keyword field is indexed for performance mapping.query(); // Initialize assignment group

var assignmentGroup = null; // Check if we have a matching record

if (mapping.next()) {

assignmentGroup = mapping.u_assignment_group; // Replace with your group field name

} // If a mapping was found, assign the incident to the group

if (assignmentGroup) {

var incident = new GlideRecord('incident');

if (incident.get(email.reference)) {

incident.assignment_group = assignmentGroup;

//incident.update();
}
 else {

gs.info ('No assignment group found for the subject: ' + subject);
}
}
current.insert();
 
The incident is getting crreated but assignment group part is not working.