Check whether additional comment is not empty

aksh3
Giga Guru

Hi Experts,

What could the best method to check if additional comment is not empty in a background and business rule.

@Ankur Bawiskar 

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.

11 REPLIES 11

suvro
Mega Sage
Mega Sage

Try below, this will return all the comments. Check if it is empty

gs.print(gs.nil(gr.comments.getJournalEntry(-1)));

suvro
Mega Sage
Mega Sage

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]);

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

comments are stored in sys_journal_field

what's your business requirement?

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar : requirement is whenever the additional comment in not empty i need to call an api in script.

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
}

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

Thank you,
Palani