Closed by the system Incidents are not completing their SLA records correctly

Ken61
Giga Guru

Hello guys,

I am having a hard time figuring out what's wrong with my SLA stop condition as it stuck in paused stage and not move into 'Completed' Stage when the incident is auto closed by the system. But when I manually close the Incident, then it completes the SLA record correctly, every time.

Here is my Stop Condition, the SLA should Stop after the Incident is Closed.

Here is my paused condition

Below is also my Auto Close Incident BR.

// This script automatically closes incidents that are resolved

// and haven't been updated in the specified number of days.

// This number is a property in System Properties.

// To place a comment in the incident, uncomment the "gr.comments" line.

 

autoCloseIncidents();

function autoCloseIncidents() {

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

               var pn = parseInt(ps);

               var queryTime = new GlideDateTime();

               queryTime.addDaysUTC(-pn);

               if (pn > 0) {

                              var gr = new GlideRecord('incident');

                              gr.addQuery('incident_state', IncidentState.RESOLVED);

                              if (gs.getProperty('com.snc.incident.autoclose.basedon.resolved_at', 'false') === 'true') {

                                             gr.addQuery('resolved_at', '<', queryTime);

                              }

                              else {

                                             gr.addQuery('sys_updated_on', '<', queryTime);

                              }

                              if (pm.isActive('com.snc.incident.mim')) {

                                             var mim = gr.addNullQuery('major_incident_state');

                                             mim.addOrCondition('major_incident_state', '!=', new sn_major_inc_mgmt.MajorIncidentTriggerRulesSNC().MAJOR_INCIDENT_STATE.ACCEPTED);

                              }

                              gr.query();

                              while(gr.next()) {

                                            

                                             gr.incident_state = IncidentState.CLOSED;

                                             gr.setValue('state', 7);

                                             //  gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';

                                             gr.active = false;

                                             gr.closed_by = gr.resolved_by;

                                             gr.closed_at = gs.nowDateTime();

                                             gr.update();

                              }

               }

}

 

Please assist on what I need to be done to get the SLA set to completed when the incident state auto closed by the system.

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hello,

Your images are not showing, please embed then using the "Insert Image" button within the reply window.

Additionally, please use the "Insert/Edit code sample" button when pasting code so that it remains organized and easier to read.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank You Allen for pointing this out. Below are the new SLA pictures and the code. I really appreciate your assistance on this.

Thanks

Ken61
Giga Guru

find_real_file.png

Pause SLA condition

Ken61
Giga Guru

find_real_file.png

Stop SLA Condition