SLA Problems

ranj2
Kilo Explorer

Hello all,

Quick question I was hoping someone might be able to shed some light on. We've set up basic SLA's in the system, and all seem to work ok unless a ticket is opened and resolved in the same instance (e.g. without creating, saving, then going back and closing). If you open/close in one, there is simply no SLA attached to the incident.

I think it might be something to do with the start condition of the SLA's (active=true) which it doesnt see when open/ resolved, but wondering anyone knows any sort of workaround for this?

Many thanks.

4 REPLIES 4

DrewW
Mega Sage
Mega Sage

I have spent an extensive amount of time going over the SLA code in its various forms and I have to say the latest code is the most difficult to "interrupt". Part of your issue is that an SLA will not be added if its stop condition is met at the time the SLA is evaluated to see if it should be attached to the ticket. The other part of your issue is that if you insert a resolved ticket it is not active so the start condition will not be met by the time the code gets around to being run.

If you want the SLA added to all incidents I would just remove the active=true condition, but that does not help you with the second part which is if the SLA's stop condition is met also it will not add and the only way to fix that is to either change the OOB SLA code or write your own.

If anyone else know a way I would love to here it we have a number of issues with the current SLA code and the only way I could fix them was to modify the OOB code.

Drew


dh4234
Kilo Expert

I modified the OOB script to accomplish this. I attached the modified script


Not applicable

The default interpretation of SLA Definition's conditions means that if the Stop Condition is true and the Start Condition is true for the first time, then we don't add the SLA (this is just default behaviour that we've always had.)

This is exactly why SLA Condition Rules were created.

SLA Condition Rules allow you to choose how the start/stop/pause/reset conditions of an SLA definition are interpreted.

(see http://wiki.service-now.com/index.php?title=Modifying_SLA_Condition_Rules for the documentation)

The great thing about SLA Condition Rules is that you never need to alter the out of the box code (dh4234 - I'd value feedback on how we could make that clearer) because we provide a way for you to write your own or extend ours (and we give "SLAConditionSimple" as an example, but also as a simplified form that might be useful for some customers.)

You extend the SLAConditionBase Class by creating your own Script Include and extending it in the usual way, overriding the attach() method according to your requirements. Then create the SLA Condition Rule entry, with a name for it and pointing to the Script Include Class that you created:



var U_mySLACondition = Class.create();
U_mySLACondition.prototype = Object.extendsObject(SLAConditionBase, {
attach: function() {
return this._conditionMatches(this.sla.start_condition);
});


The above would override the attach() method to add an SLA whenever the SLA start condition (only) is met. Then you can either make the default be your own Condition Rules implementation, or you can set it on a per SLA Definition basis.

Slightly Loony's blog has a piece on extendsObject, if you are unfamiliar with the syntax (Scripting: Extending a Class, Part III...) - although we use it extensively in Script Include Classes if you look closely, e.g. anything that implements an AJAX interface.

The 'active=true' flag though - that's only tested on the contract_sla records, not the task/incident itself. We leave that up to you, in the conditions you define for your SLAs.


Dominik Simunek
Tera Guru

I had similar requirement to create Task SLAs even if the Task was updated in a way that Stop Condition of SLA was met in the same time as Start Condition. Customer expected Task SLA to be created and immediately set to Completed stage. I would like to share the piece of solution as it might be helpful to somebody.



ServiceNow describes options how to override SLA Condition Rules as @jamesrgrinter already wrote. There is one called SLAConditionSimple which attaches Task SLA if Start Condition is met (compare to SLAConditionBase were also Stop Condition cannot be met). I tried to use this one first, but the result was that any other update of Task resulted in second, third, fourth Task SLA for the same SLA Definition to be created if Start Condition was still met. But the expectation was to create it only once directly in Completed stage. I resolved it via custom script include extending SLAConditionBase.



var SLAConditionCustom = Class.create();


SLAConditionCustom.prototype = Object.extendsObject(SLAConditionBase, {



  /**


  * Start SLA if start_condition is true, but also when stop_condition is complete in case


  * there is no already completed SLA for it.


  * Ensures Task SLAs are created even when start and stop entries are provided in one update.


  *


  * @return {boolean} true if sla should be attached to task


  */


  attach: function() {


        this.lu.logInfo('SLAConditionCustom.attach called');


        var startMatches = this._conditionMatches(this.sla.start_condition);


        // start condition matches - second part only makes sure that such completed is created only once, not for every update


        // check first for complete and then for completed exists to avoid GlideRecord query if not going to be completed


        return startMatches && !(this.complete() && this._completedAlreadyExists());


  },



  /**


  * Returns true if there is completed Task SLA for task and sla combination.


  *


  * @return {boolean} true if there is already completed concrete sla for the task


  */


  _completedAlreadyExists: function() {


        var taskSlaGR = new GlideRecord('task_sla');


        taskSlaGR.addQuery('sla', this.sla.getValue('sys_id'));


        taskSlaGR.addQuery('task', this.task.getValue('sys_id'));


        taskSlaGR.addQuery('stage', 'completed');


        taskSlaGR.setLimit(1);


        taskSlaGR.query();


        return taskSlaGR.hasNext();


  },



  type: 'SLAConditionCustom'


});



You need to change the system property to use this script include for SLA engine.