Update comments in incident by using background script

Shaik22
Tera Expert

Hi,

 

I wrote a background script to update the comments in incident table But didn't update the comments. Please help

Script: 

var gr = new GlideRecord('incident');
gr.get('88041f451b080d1039068550604bcb2d');
gr.comments = 'As requested, closed the incident record';

//gr.autoSysFields(false);
//gr.setWorkflow(false);
gr.update();

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

You should always use get in an if condition.  This way you can confirm that the record was retrieved.

 

var gr = new GlideRecord('incident');
if (gr.get('88041f451b080d1039068550604bcb2d')) {
   gs.print('Incident record found ' + gr.number);
    gr.comments = 'As requested, closed the incident record';
    //gr.autoSysFields(false);
    //gr.setWorkflow(false); 
    gr.update();
} else {
    gs.print('Incident record not found.);
}

Other than ensuring you are using a valid incident sys_id, a similar Fix Script works fine in my PDI.

 

I wrote script and it is not updating the record.

Shaik22_0-1724934509394.pngShaik22_1-1724934566472.png

 

So CTRL0020372 is a record on the incident table which you are showing in the screenshot?  Do you have permission to add a comment to this record manually? I'm not seeing a Post button.

No i don't have permission to add manually. what should i have to do?