SLA creation based on Item field

TulikaA
Tera Contributor

Hi All,

 

We have a requirement to create SLA based on the delivery time field of the catalog item. The resolution type SLA should have duration same as the number of days mentioned in the delivery time of the item.

 

Any feasible solution will be helpful.

 

Thank you!

2 REPLIES 2

Yousaf
Giga Sage

Hi TulikaA,

1. Create an SLA to fire on the lowest priority and set some default value for duration because it is a required field.
2. There is a before business rule which runs on Insert on the task_sla table called "Set planned end time". This script populates the planned end time field on the Task SLA. Modify this script to look at the new End Time field and if populated then use this to set the "Planned End Time" for the SLA.

You could do the same thing with a Catalog Item by looking at the delivery time field. An example of the calculation is in the business rule because the duration field on the SLA definition is the same field type as the Catalog Item delivery time field - glide_duration.

 

Reference: SLA duration based on Catalog Item 

 

Mark Correct and Helpful if it helps.


***Mark Correct or Helpful if it helps.***

TulikaA
Tera Contributor

Hi Yousaf,

 

Thank you for the solution.

We have tried, but was not able to retrieve the delivery time. 

Could you please have a look at it?

setPlannedEndTimeNew();

 

function setPlannedEndTimeNew() {

     var deltime = '00'; // new GlideDuration('0 00:00:00');

    var ritm = new GlideRecord("sc_req_item");

    ritm.addQuery('sys_id', current.task);

    ritm.addQuery('active', true);  

    ritm.query();

    if (ritm.next()) {

 

        var gr = new GlideRecord("sc_cat_item");

        gr.addQuery('sys_id', ritm.cat_item);

        gr.query();

        if (gr.next()) {

 

       

            deltime = gr.delivery_time.getDisplayValue();

 

                }

    }

 

    //CAlCULATION Starts

    var dur = new DurationCalculator();

    var tz;

    if (current.timezone)

        tz = current.timezone;

    else

        tz = gs.getSysTimeZone();

 

    dur.setSchedule(current.schedule, tz);

    dur.setStartDateTime(current.start_time);

    if (current.sla.duration_type == "") {

    var totalDur = deltime.getGlideObject().getNumericValue() + current.business_pause_duration.getGlideObject().getNumericValue();

       

        dur.calcDuration(totalDur / 1000);

    } else {

        dur.calcRelativeDuration(current.sla.duration_type);

   }

    current.planned_end_time = dur.getEndDateTime();

   

    if (current.active == true) {

        //Create a trigger

        var newTrigger = new GlideRecord("sys_trigger");

        newTrigger.name = 'SLA breach timer - ' + current.task.number + ' - ' + current.sla.name;

        newTrigger.next_action = current.planned_end_time;

        newTrigger.document = 'task_sla';

        newTrigger.document_key = current.sys_id;

        newTrigger.script = "var sla = new GlideRecord('task_sla'); sla.addQuery('sys_id', '" + current.sys_id + "'); sla.query(); if (sla.next()) { sla.stage = 'breached'; sla.update();}";

        newTrigger.job_id.setDisplayValue('RunScriptJob');

        newTrigger.trigger_type = 0;

        newTrigger.insert();

    }

 

}