I have to create Inbound action.

niveditakumari
Mega Sage

Hi Team, 

 

I have to create Inbound action and in that I need to check recipient and based on recipient it will create HR case and assign that. 

 

Requester = Guest
Subject Person = Guest
Source = Email
External Requester = True
Short Description = Email subject
Current script Line1-Line7
Above are common field that should be available in both HR case and when email is coming from workday then HR case will be created with above value for both HR case and when email recipient is robinhoodprod@service-now.com then add other field value as well like mentioned

4) if (recipient is robinhoodprod@service-now.com) do below 
Category = People Systems Request
Subcategory = Workday
HR Service = Workday - Support/Break-Fix
Function = Other
Type = Integration
Assignment Group = HR Tier 2 - People Systems
Current script Line9-Line37 


And when email recipient is hr@robinhood.com then create HR case with other field value as mentioned

else if(recipient is hr@robinhood.com) do below
Category = General People Request
Assignment Group = HR Tier 1 - People Support to check two recipient and based on that need to create HR case assign that. 

 

Can you please help me to create Inbound action for that. 

 

Regards, 

Nivedita 

 

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron

@niveditakumari 

so where are you stuck?

what debugging did you do?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar , 

 

I have written script and I need to test that. 

Please my attached code : 

var bodyText1 = email.body_text;

if (!bodyText1)
bodyText1 = email.body_html;

current.rich_description = email.body_html; //// Define a regular expression pattern to match "Assign To: " followed by a name
current.u_requester_email = email.from;

var hrEmail = gs.getProperty("sn_hr_core.RH_HRRobinhoodEmail", "hr@robinhood.com");
var rhProdEmail = gs.getProperty("sn_hr_core.RH_RobinhoodProdEmail", "robinhoodprod@service-now.com");
var tier1GroupName = gs.getProperty("sn_hr_core.People Support", "HR Tier 1 - People Support");
var tier2GroupName = gs.getProperty("sn_hr_core.tier_2_hr_system","HR Tier 2- People Systems ");
if (email.to == rhProdEmail) {

current.category = "People Systems Request";
current.subcategory = "Workday";
current.u_hr_service = "Workday - Support/Break-Fix";
current.function = "Other";
current.type = "Integration";
current.assignment_group = tier2GroupName;

var assignToRegex = /Assign To:\s*([^\n]+)/; // Execute the regular expression to extract the name
var match = assignToRegex.exec(bodyText1);
if (match && match[1]) {
// Extracted name from the email body
var assignedToo = match[1].trim();

var userID = new GlideRecord("sys_user");


userID.addQuery('name', assignedToo.trim());


userID.query();

if (userID.next()) {
var assignedToSysId = userID.getUniqueValue();

current.assigned_to = assignedToSysId;
// Set state based on assigned_to field
if (current.assigned_to.nil()) {
current.state = '10'; //STATE IS READY
} else {
current.state = '18'; //STATE IS WORK IN PROGRESS
}

}
}
} else if (email.to == hrEmail) {

current.category = "General People Request";
current.assignment_group = tier1GroupName;
 1. System property 
niveditakumari_0-1768632841826.png 

 

 
2. System property
niveditakumari_1-1768632903706.png
 
3. Inbound Action 
 
niveditakumari_2-1768632975966.png

 

 

 

In "if" it is checking recipient id with system property and in current.assignment_group it is checking system property to set assignment group. 
I have sent email from my mailbox to servicenow non prod instance and Find the record in sys_email table -> then in header updated from address to robinhood@myworkday.com and To address to satisfy my inbound action condition and then updated Recipient details accordingly -> Save the record -> Reprocessed the record. 
 
When I'm sending email from my mailbox to non prod instance it is creating log in system and after that I'm reprocessing that email record with my test id's it is not creating email log or HR case. 
Ideally it should create emails for reprocessed email and create HR case with having field value added in Inbound action. 
Can you please help me to correct that and test that.
 
Regards, 
Nivedita 
 
 

@niveditakumari 

you need to debug inbound action step by step if somewhere it's failing or not

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar

 

Can you please help me to debug that. 

 

Regards, 

Nivedita