- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 07:37 AM
Hi
I am trying to add the most recent Sent/Received email journal field to a client email template but I cant seem to get it to work.
I found this script to add work notes to the email to see if it works so I can then amend it to show the most recent Sent/Received email but it doesn't seem to return anything, What am I doing wrong?
var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n' var na = notes.split("\n\n"); //stores each entry into an array of strings for (var i = 0; i < na.length; i++) gs.print(na[i]);
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 07:58 AM
Hi Russel,
The code you have mentioned above is correct. I believe, the implementation you are trying to achieve is confusing/semantically incorrect.
If I understand your question right, you want to show the Sent/Received emails(shown on the activity of a record) on an outbound email?
This is possible only if it is an actual field. The data showed in the activity log is based on Audit table and relations to sys_email table. So may want to create a code for the same like:
var gr = new GlideRecord("sys_email");
gr.addQuery("instance",current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
//Now gr will contain all the emails sent or received for the target record.
//If you want to restrict is to a number then
var gr = new GlideRecord("sys_email");
gr.addQuery("instance",current.sys_id);
gr.setLimit(3);//put the max number here
gr.orderBy("sys_created_on");
gr.query();
//The field on the addQuery statement was a mistake.It should be "instance". This would do the trick.
Make sure you let us know, how it went after trying this.
Regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 07:44 AM
Hi,
Please replace the whole script with below code for latest entry in email script and make sure there is an entry existing.
var notes = current.work_notes.getJournalEntry(1);
template.print(notes);
Regards,
Ram M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 07:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 08:35 AM
Hi Russell,
Email is not updated in work notes unless in your inbound action if you have added the script to populate the body of the email in the worknotes.
Regards,
Ram M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2018 07:58 AM
Hi Russel,
The code you have mentioned above is correct. I believe, the implementation you are trying to achieve is confusing/semantically incorrect.
If I understand your question right, you want to show the Sent/Received emails(shown on the activity of a record) on an outbound email?
This is possible only if it is an actual field. The data showed in the activity log is based on Audit table and relations to sys_email table. So may want to create a code for the same like:
var gr = new GlideRecord("sys_email");
gr.addQuery("target",current.sys_id);
gr.orderBy("sys_created_on");
gr.query();
//Now gr will contain all the emails sent or received for the target record.
//If you want to restrict is to a number then
var gr = new GlideRecord("sys_email");
gr.addQuery("target",current.sys_id);
gr.setLimit(3);//put the max number here
gr.orderBy("sys_created_on");
gr.query();
Make sure you let us know, how it went after trying this.
Regards,
Sagar