gr.updateMultiple(); doesn't update comments in incident records

kushal_dangare
Tera Expert

Hi,

 

I am trying to run below script to close incidents in Servicenow. The script is working fine but the comments are not getting updated in incident records. If I try to implement it using while loop, comments are getting updated correctly. But it doesn't work with gr.updateMultiple();

And I need to use only gr.updateMultiple(); in this particular case.

 

var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);

var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.setLimit(1000);
gr.addEncodedQuery('u_major_incidentISEMPTY^ORu_major_incident=false');
gr.addQuery('state', '6');
gr.addQuery('sys_updated_on', '<', gs.daysAgo(pn));
gr.orderByDesc('sys_updated_on');
gr.query();
gr.setValue('state', 7);
gr.setValue('active', false);
gr['comments'].setJournalEntry("Incident automatically closed after "+pn+" days in the Resolved state.");
gr.updateMultiple();

 

Thanks,

Kushal.

2 REPLIES 2

Alikutty A
Tera Sage

Have you tried this?

gr.setValue('state', 7);
gr.setValue('active', false);
gr.setValue('comments',"Incident automatically closed after "+pn+" days in the Resolved state.");
gr.updateMultiple();

Andrew Barnes -
ServiceNow Employee
ServiceNow Employee

Greetings Kashai,

 There is already an out of box feature to close incidents that is set via a property. https://docs.servicenow.com/bundle/helsinki-it-service-management/page/product/incident-management/t...

You can even configure the template for the closure via a link from the docs page as well. You can check out the business rule that handles this: https://instance.service-now.com/nav_to.do?uri=sys_script.do?sys_id=d67b8d9ec0a80118008cd8f0f7f92fae and adjust its conditions/filters and remove the commented like on line 30 to handle your use case.

-Andrew Barnes
Join me at Developer Blog