- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 01:44 AM
I have a Inbound email actions to create catalog request item. While the request is created I want to add the inbound email to the request activity like the email sent below.
I found the "Target" is empty in sys_email.
Is there anyway to set the target from the inbound email action script so the email can be found in activity?
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// look for existing Email to Case
var gr = new GlideRecord("sc_req_item");
var str = email.subject;
var text = str.substr(str.indexof("FW:"), 3);
text = str.replace("FW:", "").trim();
gs.info("[Email to Case]text = " + text);
gr.addQuery("short_description", "CONTAINS", text);
gr.query();
if (gr.next()) {
gs.info("[Email to Case] updating worknotes");
gr.work_notes = email.body_text;
gr.update();
}
//did not find it so we need to create a new request
else {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('ce6ee3e3db70101010af14613996321a');
cart.setVariable(item, 'issue_category', '5');
cart.setVariable(item, 'issue_details', email.body_text);
sys_email.target_table = current.getTableName();
sys_email.instance = current.sys_id;
sys_email.update();
var rc = cart.placeOrder();
updateRITM(rc.sys_id);
}
function updateRITM(req) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', req); //req is what we passed from the previous function. the sys_id of the request.
ritm.query();
while (ritm.next()) {
ritm.due_date = email.body.start_date;
ritm.comments = "Request by: " + email.origemail + "\n\n" + email.body_text;
ritm.short_description = email.subject;
ritm.u_is_email_create = 'true';
ritm.contact_type = "Email";
ritm.update();
}
}
//now update the email record so it will show up in the record's activity formatter
logger.logInfo("Processing 'Email Record'");
//sys_email.target_table = "sc_req_item";
sys_email.target_table = current.getTableName();
sys_email.instance = current.sys_id;
sys_email.update();
event.state = "stop_processing";
})(current, event, email, logger, classifier);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2020 11:28 PM
Hi,
The email activity shows only when the inbound action has updated the current record. Only then it can link the email with the associated record. In your code, you are fetching the record using gliderecord query and updating the gr, but not the current.
Hence the email activity is not showing in that specific record as SN considers that as a regular update and not through inbound action.
Mark the comment as a correct answer and also helpful if this has answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 02:57 AM
HI Kelvin ,
Here i can see that you are trying to update the current record as given below
sys_email.target_table = current.getTableName();
sys_email.instance = current.sys_id;
sys_email.update();
But it should be updated with the sys_id of RITM .
It should be
sys_email.target_table = 'sc_req_item';
sys_email.instance = ritm.sys_id;
sys_email.update();
Please mark helpfull if it helped you in any way.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2020 04:11 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2020 11:28 PM
Hi,
The email activity shows only when the inbound action has updated the current record. Only then it can link the email with the associated record. In your code, you are fetching the record using gliderecord query and updating the gr, but not the current.
Hence the email activity is not showing in that specific record as SN considers that as a regular update and not through inbound action.
Mark the comment as a correct answer and also helpful if this has answered your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 11:57 PM
Kindly mark the comment as a correct answer if this has answered your question.