Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Inbound Action Assign to assigned to

manumanoj
Tera Contributor

Hi All

Based on recipient to assign to assigned TO how to achieve this please suggest

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@manumanoj extract recipient email in the Email Action script, find the corresponding user by querying the sys_user table and addQuery('email', email.to.toString().split(',')[0]); email.to returns comma separated list of recipients.

 

once you find the user. 

 

current.assigned_to = glideUser.getValue('sys_id');

 

Hope this helps.

View solution in original post

9 REPLIES 9

Sorry mate, need to check , possible to share code screenshot also did yu check in email logs is this user id is coming properly.

 

@Sandeep Rajput any thoughts

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

 

Hi @Sandeep Rajput @Dr Atul G- LNG here is the logic please correct me if any thing wrong

manumanoj_0-1718256688812.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);
}

Sandeep Rajput
Tera Patron
Tera Patron

@manumanoj extract recipient email in the Email Action script, find the corresponding user by querying the sys_user table and addQuery('email', email.to.toString().split(',')[0]); email.to returns comma separated list of recipients.

 

once you find the user. 

 

current.assigned_to = glideUser.getValue('sys_id');

 

Hope this helps.

Hi @Sandeep Rajput @Dr Atul G- LNG Here is the logic please correct me if any thing wrong

manumanoj_0-1718250620516.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);
}

Hi @Sandeep Rajput 

 

here is the logic not able to update showing error that in logs 

The selected 'Recipients in fields' - 'assigned_to' does not have value

Please suggest how that can resolve

gs.log('Creating GlideRecord for sys_user...');
var user = new GlideRecord('sys_user');

var firstRecipient = email.to.toString().split(',')[0];
gs.log('Adding query for email: ' + firstRecipient);
user.addQuery('email', firstRecipient);

gs.log('Executing query...');
user.query();

gs.log('Checking if query returned any records...');
if (user.next()) {
    gs.log('User found with email: ' + firstRecipient);
    gs.log('Assigning current record to found user...');
    current.assigned_to = user.getValue('sys_id');
else {
    gs.log('No user found with email: ' + firstRecipient);
}
gs.log('Ending script...');