Check whether additional comment is not empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 10:25 PM
Hi Experts,
What could the best method to check if additional comment is not empty in a background and business rule.
var gr = new GlideRecord('incident');
gr.get('b64f102567f551101a1136dbd36d434d');
gs.print(gr.number);
gs.print(JSUtil.nil(gr.comments));
//gs.nil()
based upon which i wish to call an api. Please help.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 11:17 PM
Try below, this will return all the comments. Check if it is empty
gs.print(gs.nil(gr.comments.getJournalEntry(-1)));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 11:19 PM
Code for getting the contents of a journal field into an array
To put the contents of a journal field into an array so that you can iterate through each entry, you can use the code in this page.
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]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 11:22 PM
Hi,
comments are stored in sys_journal_field
what's your business requirement?
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2022 12:08 AM
right now the below code works fine in BR , is that JSutil will fail in any condition.
if(!JSUtil.nil(current.comments.toString())){
//api call
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2022 12:16 AM
Hi,
This will work only from Business Rule if you use current object. current.comments will have only value passed from the recent update. If there is a value in comment already and you are just changing State value then current.comments will be blank while BR is executing.
If you are querying your data from GlideRecord then you should always use getJournalEntry
Palani