Unable to set "Requested_For" from email body in RITM via inbound action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:47 AM
Hi Dev's.
I am working on a requirement were I have to capture an email from a specific email id via inbound action and then create an RITM with 1 associated TASK.
Field values will be captured from email body and both RITM & TASK fields should have same fields values.
Sol: I tried making an dummy catalog item and attached a workflow, (RITM & TASK creation issue solved)
Issue : I am unable to Set RITM & task "requested_for" field from email body which will be dynamic
My Inbound Action Script :
-----------------------------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:18 AM
Have you checked logs..?? are you getting logs...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:31 AM
Have done some changes in your script
cart.placeOrder(); // will return the sys_id of request & not ritm so you need to first glide record on Request table to set requested for & then ritm.
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
//Implement email action here
var cartID = GlideGuid.generate(null);
var cart = new Cart(cartID);
var item = cart.addItem('575c738533f1b510eb275f49bd5c7bca');
cart.setVariable(item, 'sn_req_app', '1');
cart.setVariable(item, 'sn_req_details', 'Sample text');
var rc = cart.placeOrder(); //we will get the sys_id of request
var ritmRec = new GlideRecord("sc_request"); //Glide on request table
ritmRec.addQuery("sys_id", rc.sys_id); //query with sys_id
ritmRec.query();
if (ritmRec.next()) {
ritmRec.short_description = email.subject.toString();
ritmRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
ritmRec.contact_type = "email";
//added logic for Requested For
if (email.body.name != undefined) {
var gr = new GlideRecord("sys_user");
gr.addQuery('name', email.body.name);
gr.query();
if (gr.next()) {
ritmRec.requested_for = gr.sys_id;
gs.log('abcd'+ gr.sys_id);
}
ritmRec.update();
// current.requested_for = email.body.name;
// gs.log(email.body.name);
}
}
else {
var stringbody = email.body_text.replace(/\n/g, "<br>");
var stringbody1 = stringbody.replace(/ /g, '');
var index = stringbody1.search("Name");
var namestring = stringbody1.substr(parseInt(index), 20).split(":");
current.requested_for = namestring[1];
}
//Update target in email table, as it won't be updated as the record was inserted through cart API
if (rc !='') {
var email_rec = new GlideRecord('sys_email');
email_rec.get(sys_email.sys_id);
email_rec.instance = rc.sys_id;
email_rec.target_table = "sc_request";
email_rec.update();
}
})(current, event, email, logger, classifier);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 03:28 AM
Hi Vishal,
Problem remains same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:45 AM
instead of
if (email.from != undefined) {
var gr = new GlideRecord("sys_user");
gr.addQuery('email', email.from);
gr.query();
if (gr.next()) {
ritmRec.requested_for = gr.sys_id;
gs.log('abcd'+ gr.sys_id);
}
Regards,
Piyush Sain
