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

Tushar
Kilo Sage
Kilo Sage

Hi @Alon Grod 

 

Please try below - 

 

var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_id=422122f79dc1311020d2b7cbb48c1914');
gr.query();
if (gr.next()) {
  gr.work_notes = 'Please reopen this incident.'; // Use the work_notes field for additional comments
  gr.update();
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

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

Thx!

This syntax

comInc.comments = "Please reopen this incident.";

worked for me

instead of 

comInc.setValue('comments','Please reopen this incident.');

 

sushma9
Tera Contributor

@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!