How to get last comment from sys_journal_field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 02:41 PM
I'm trying to get the last comment of a current problem from the sys_journal_field table to avoid getting header (timedate stamp, etc.) information. I'm using the function below in a business rule. I thought if I ordered descending and set the limit to one, I would get the most recent comment. However I'm not getting the most recent comment nor the oldest but one in between. What am I doing wrong? Thanks.
function resolveRelatedIncidents(me) {
//Get comments from problem through sys_journal_field in order to avoid duplicate header information when copied to incident.
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', me.sys_id);
gr.addQuery('name', 'task');
gr.addQuery('element', 'comments');
gr.orderbyDesc('sys_created_on');
gr.setLimit(1);
gr.query();
while (gr.next()) {
//Store last comment in variable
var lastComment = gr.value.toString();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 03:56 PM
Hi Carol,
You need to capitalize the "b" in OrderByDesc:
gr.orderByDesc('sys_created_on');
orderbyDesc is not a valid method (method namess are case-sensitive).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2015 08:39 AM
Thanks Cory. I was hoping it was that easy. Sometimes you just need a second set of eyes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 11:58 PM
And this can be replaced with a 'if condition'
while (gr.next()) {