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

palanikumar
Mega Sage

Hi,

Comments is a Journal entry. So, try this

var gr = new GlideRecord('incident');
gr.get('b64f102567f551101a1136dbd36d434d');
gs.print(gr.number);

gs.print(gs.nil(gr.comments.getJournalEntry(1)));
Thank you,
Palani

@palanikumar : Thanks for your response.

May i please know why the below code will fail in BR.

(JSUtil.nil(gr.comments))

Hi,

for Journal fields, data is not stored as plain text. So gr.comment will always return blank value.

The command I shared will check whether Journal has atleast one entry

Thank you,
Palani

Mahendra RC
Mega Sage

Hello Aksh,

You will not be able to find if the comments is empty or not using the background script. These can be changed while insert or update operation happening on the incident table. you can check the last comment added on incident using 

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

If you want to check the comments field is empty or not then I think you can create a before update BR with below script:

 

if(current.comments.changes()) {
// write your code here
}

Please mark my respsone as helpful/correct, if it answer your question.

Thanks