Auto Assigning incident to based on recipient email address inbound action script

sreenisola
Tera Contributor

Hello All,

 

I am trying to assign the incident to assignment group based on the receipient email address. 

we have setup like users sent email to lets say abc@domain.com which creates the incidents based on imap/smtp and inbound actions script. Incident getting created but its not assigning to automatically to assignment group (AssignmentGroup1)

 

my inbound action script is like below.

 

// Note: current.opened_by is already set to the first UserID that matches the From: email address
var assignmentGroup = determineAssignmentGroup(recipientEmail);
var recipientEmail = email.original_recipient;
   
 
current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.description = email.body_text;
current.short_description = email.subject;
current.watch_list = current.watch_list + ',' + email.copied;
 
current.category = "NEW";
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;
   }
}
 
if (assignmentGroup) {
    current.assignment_group = assignmentGroup;
} else {
       gs.log("No assignment group found for incident received via email from: " + recipientEmail);
   }
   
function determineAssignmentGroup(emailAddress) {
    if (emailAddress.indexOf('abc@domain.com') !== -1) {
        return 'AssignmentGroup1'; // Assign to the Example Assignment Group
    } else {
        return null; // Return null if no assignment group found
    }}
 
current.insert();
 
 
 
 
 
 
2 ACCEPTED SOLUTIONS

SanjivMeher
Kilo Patron
Kilo Patron

Fix below script

var recipientEmail = email.origemail;

var assignmentGroup = determineAssignmentGroup(recipientEmail);
 
Also instead of AssignmentGroup1, you need to use the sysid of the assignment group.
 

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

Subhashis Ratna
Tera Guru

Hi @sreenisola 

I have updated the OOTB code , you can try this logic to full fill your requirement .

Inbound Action Code :

SubhashisRatna_0-1712391023883.png

 

 

//	Note: current.opened_by is already set to the first UserID that matches the From: email address
//var recipientEmail = email.from;    //Option 1
//var recipientEmail = email.direct; //Option 2
var recipientEmail = email.origemail;
var assignmentGroup = determineAssignmentGroup(recipientEmail);

current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.category = "inquiry";
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;
    }
}
if (assignmentGroup) {
    current.assignment_group = assignmentGroup;
} else {
    gs.log("No assignment group found for incident received via email from: " + recipientEmail);
}

function determineAssignmentGroup(emailAddress) {
    if (emailAddress.toLowerCase().indexOf('abc@domain.com') > -1) {
        return 'sys_id_of_Assignment_group';
    } else {
        return false;
    }
}
//if (current.canCreate())
current.insert();

 


If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna

View solution in original post

11 REPLIES 11

Hi @manumanoj 

Use this code

// Note: current.opened_by is already set to the first UserID that matches the From: email address
var recipientEmail = email.origemail;
var assignmentGroup = determineAssignmentGroup(recipientEmail);
var assignedToUser = determineAssignTo(recipientEmail);

current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.category = "inquiry";
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;
    }
}

if (assignmentGroup) {
    current.assignment_group = assignmentGroup;
} else {
    gs.log("No assignment group found for incident received via email from: " + recipientEmail);
}

function determineAssignmentGroup(emailAddress) {
    if (emailAddress.toLowerCase().indexOf('abc@domain.com') > -1) {
        return 'sys_id_of_Assignment_group';
    } else {
        return false;
    }
}

function determineAssignTo(emailAddress) {
    var assignToUser;

    var userGr = new GlideRecord('sys_user');
    userGr.addQuery('email', emailAddress);
    userGr.query();

    if (userGr.next()) {
        assignToUser = userGr.getUniqueValue(); 
    } else {
        gs.log("No user found for email address: " + emailAddress);
    }

    return assignToUser;
}

if (assignedToUser) {
    current.assigned_to = assignedToUser;
} else {
     current.assigned_to = "sys_id_of_default_user"; // You can use any user sysid based on your req.
    gs.log("No user found for assignment for incident received via email from: " + recipientEmail); 
}

// if (current.canCreate())
current.insert();


If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna

Hi @Subhashis Ratna how we can achieve that recipient to to assigned to

Please suggest