We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

I have created inbound action and it should create req and ritm.

niveditakumari
Giga Sage

Hi, 

 

I have created inbound action and it should create req and ritm and it should email target in email log record. 

I have written code and it is creating req and ritm and it is not adding ritm to email target. 

(function runAction(current, email, event) {

// Create REQ
var req = new GlideRecord("sc_request");
req.initialize();
req.short_description = "Device Unlock Request";
req.description = "Created from inbound email";
var reqSysId = req.insert();

// Create RITM
var ritm = new GlideRecord("sc_req_item");
ritm.initialize();
ritm.request = reqSysId;
ritm.cat_item = gs.getProperty("rh_device_unlock_request");
ritm.short_description = "Device Unlock Request - " + new GlideDate().getDisplayValue();
ritm.description = email.body_text;
ritm.priority = 3;
ritm.assignment_group = gs.getProperty(
"rh_tier_1_support_engineering",
"Tier 1 - Support Engineering"
);
ritm.insert();

})(current, email, event); 
 
I have to create req and ritm and in email log record target should be added as ritm.
Can you please correct code to achieve that.
 
Regards,
Nivedita 
 
 
10 REPLIES 10

Ankur Bawiskar
Tera Patron

@niveditakumari 

try this

(function runAction(current, email, event) {

// Create REQ
var req = new GlideRecord("sc_request");
req.initialize();
req.short_description = "Device Unlock Request";
req.description = "Created from inbound email";
var reqSysId = req.insert();

// Create RITM
var ritm = new GlideRecord("sc_req_item");
ritm.initialize();
ritm.request = reqSysId;
ritm.cat_item = gs.getProperty("rh_device_unlock_request");
ritm.short_description = "Device Unlock Request - " + new GlideDate().getDisplayValue();
ritm.description = email.body_text;
ritm.priority = 3;
ritm.assignment_group = gs.getProperty(
"rh_tier_1_support_engineering",
"Tier 1 - Support Engineering"
);
ritm.insert();

sys_email.target_table = "sc_req_item";
sys_email.instance = ritm.sys_id;
sys_email.update();

})(current, email, event);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@niveditakumari 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi @Ankur Bawiskar

 

Above code not working for reprocessed email and it is working for when email is sent from that id which we have added in from address in inbound action. 

Can you please help me to correct code for reprocessed email. 

 

Regards, 

Nivedita 

 

 

@niveditakumari 

Since you said it's working fine when email is coming from that ID then it means script I gave is correct.

no code required for reprocessed email.

Simply test with fresh email or clear the target and test again by re-processing.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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