Incident Management:I need a background script to update the closed date with the update date for incidents.

PDeGraw
Tera Contributor

So for some odd reason the "autoclose incident" business rule stopped entering the close date even though it is changing the state to close.

So now I have over 700 tickets that are no longer active and state is closed but is missing a closed date.

If I can just populate the update date to the closed date field then we can run our reports properly. Without a closed date I am having problems with reporting.

Here is what I have so far but it didn't work. Any assistance would be appreciated.

var inc = new GlideRecord('incident');

inc.addQuery('active','false');
inc.addQuery('state','7');
inc.addQuery('closed_at','null');

inc.query();

var count = 0;

while(inc.next()){

count++;

inc.sys_updated_on = inc.closed_at;

inc.update();

}

gs.print(count);

1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage
Giga Sage

Hi Pam,


                Try this.


var inc = new GlideRecord('incident');



inc.addQuery('active','false');
inc.addQuery('state','7');
inc.addQuery('closed_at','null');


inc.query();


var count = 0;



while(inc.next()){


count++;


iinc.closed_at=nc.sys_updated_on ;


inc.update();


}


gs.print(count);


View solution in original post

4 REPLIES 4

Gangadhar Ravi
Giga Sage
Giga Sage

Hi Pam,


                Try this.


var inc = new GlideRecord('incident');



inc.addQuery('active','false');
inc.addQuery('state','7');
inc.addQuery('closed_at','null');


inc.query();


var count = 0;



while(inc.next()){


count++;


iinc.closed_at=nc.sys_updated_on ;


inc.update();


}


gs.print(count);


I see what I did wrong. Thanks for the assist.


Mike Patel
Tera Sage

On sysauto_script.list create new



var gr = new GlideRecord('incident');


gr.addEncodedQuery('closed_atISEMPTY');


gr.addEncodedQuery('active=false');


gr.query();




while(gr.next()){


  gr.closed_at = gr.sys_updated_on;


  gr.update();


}


PDeGraw
Tera Contributor

Thanks for all the assist. Here is the final code that I used.


var gr = new GlideRecord('incident');


gr.addQuery('active', false);


gr.addQuery('state', 7);


gr.addQuery('closed_at', '');


gr.query();


while (gr.next()) {


gr.closed_at = gr.sys_updated_on;


gs.print('ticket modified: ' + gr.number + ', updated date: ' + gr.sys_updated_on + ', close date: ' +


gr.closed_at);


gr.setWorkflow(false);


gr.update();


}