How to populate additional comments with value using script

Alon Grod
Tera Expert

Hi,

How can I insert a comment into additional comments on incident table using script, i tried with this script but I had no luck:

 

var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_id=422122f79dc1311020d2b7cbb48c1914');
gr.query();
if(gr.next()){
gr.comments.setJournalEntry('Please reopen this incident.');
gr.upadte();

}

  

1 ACCEPTED SOLUTION

jonsan09
Giga Sage
Giga Sage

You can try the following:

var comInc = new GlideRecord('incident');
comInc.get('422122f79dc1311020d2b7cbb48c1914');
comInc.query();
while(comInc.next()) {
    comInc.comments = "Please reopen this incident.";
    comInc.update();
}

 

The setJournalEntry is add additional attributes to the comment, you can find more info on it here: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0748347

View solution in original post

7 REPLIES 7

sushma9
Tera Contributor

Hi @Alon Grod 

@Alon Grod 

Please find the Script  below.

 Script :

var gr = new GlideRecord("incident");
gr.get('ea4fb154479531108f96ba48436d437b' );
gr.query();
if(gr.next()){
gr.comments = "Please reopen this incident.";
gr.update();
}
 
Please,  Mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Chaitali_Vale
Mega Sage
Mega Sage

Hello @Alon Grod ,

You can directly add message to Default Value related after configuring the field. 

Chaitali_Vale_0-1694502344853.png

 

Chaitali_Vale_1-1694502377511.png

 

Please mark my solution as Helpful/Correct, if applicable. 

Thanks & Regards,
Chaitali Vale

DeepakK88645261
Tera Contributor

Just to add if you're using Before BR, don't use current.update();. It may lead to recursive calls and cause performance issues.