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

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.

Pratiksha Kalam
Kilo Sage

Hi,

pls check autoassign case 

 

If my answer is helpful pls mark helpful and correct!

Thank You!

Br,

pratiksha.k

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

I tried with single email it working. but where as same with multiple IDs it not working , am I doing something wrong here. 

 

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;
    }
}