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

if its more than one email id in loop its not working.

 

function determineAssignmentGroup(emailAddress) {
    if (emailAddress.indexOf('def@domain.com') !== -1) {
        return '2383001387450510f8e7ec2343435ac';
    } else if (emailAddress.indexOf('abc@domain.com') !== -1) {
        return '1383001387450510f8e7ec683cbb35ac';
    } else {
        return false;
    }
}
   

The code worked when using sys_ID but another problem I am facing is now whatever may be the recipient email address the incident getting assigned to same assignment group mentioned in code. Pls suggest what can wrong here in the code 

Hi @Subhashis Ratna  can you please suggest based on recipient To auto assign to assigned to

 

Hi @manumanoj 

Could you please share your code with me? Once I review it, I'll be able to provide you with a response along with any necessary code adjustments.

Thanks
Subhashis Ratna

Hi @Subhashis Ratna Here in body say that @xyz  it auto in recipient to  assign to assigned to

manumanoj_0-1718250185719.png

var recipientEmail = email.origemail;
var assignee = determineAssignee(recipientEmail);

gs.log("Recipient email: " + recipientEmail);

if (email.body.assign != undefined) {
    current.assigned_to = email.body.assign;
    gs.log("Assigned to from email body: " + email.body.assign);
} else {
    gs.log("No 'assign' field found in email body.");
}

if (assignee) {
    current.assigned_to = assignee;
    gs.log("Assigned to from recipient email: " + assignee);
} else {
    gs.log("No assignee found via email from: " + recipientEmail);
}

if (!current.assigned_to) {
    gs.log("Error: 'assigned_to' field is still empty.");
} else {
    gs.log("'assigned_to' field is set to: " + current.assigned_to);
}