How to design to create new response SLA tasks every time the assignment group changes on incident.

HV1
Mega Guru

Requirement is to have a new 30 min response SLA created whenever the assignment group changes on the incident.   The previous should get closed and the new one should be created. How to design SLA definition to achieve this.

1 ACCEPTED SOLUTION

A small correction. Instead of a client script, I am using a BR instead.


So here is the complete code:



STEP 1: Create following new fields on Incident table:


                            - 'Response SLA State' (u_response_sla_state) string field.


                            - 'Trigger Group' (u_trigger_group) reference field to groups.



STEP 2: Create Response SLA definition as below:


                            Screen Shot 2016-04-20 at 10.03.06 AM.png




STEP 3: Create BEFORE UPDATE business rule on incident table as below:


                          Screen Shot 2016-04-20 at 9.57.12 AM.png


                          Code:


function onBefore(current, previous) {



  //This function will be automatically called when this rule is processed.


  current.u_trigger_group = previous.assignment_group;


  current.state = 1;



  var gr = new GlideRecord("task_sla");


  gr.addQuery("task", current.sys_id);


  gr.addQuery("sla", "<sys_id of the SLA Definition record above>");


  gr.addQuery("stage","NOT IN","cancelled,completed");


  gr.query();


  if (gr.next()) {


  current.u_response_sla_state = 'complete';


  } else {


  current.u_response_sla_state = 'create';


  }



}



STEP 4: Create BEFORE INSERT/UPDATE business rule on task_sla table as below:


                              Screen Shot 2016-04-20 at 9.57.36 AM.png


                            Code:


function onBefore(current, previous) {


  //This function will be automatically called when this rule is processed.


  var task_id = current.task;


  var gr = new GlideRecord("incident");


  gr.get(task_id);


  gr.u_response_sla_state = 'create';


  gr.update();


}




This should make it work.


- Hardik Vora


View solution in original post

17 REPLIES 17

ramilo
Kilo Contributor

I have the same requirement as well. This time is on problem table. Can you show me the code on your 3rd step - onBefore BR on SLA Task table to update the incident flag again to 'create'.



Thank you.


Hi Hardik,



could you post the complete code.



Thanks,


Nagaraju


A small correction. Instead of a client script, I am using a BR instead.


So here is the complete code:



STEP 1: Create following new fields on Incident table:


                            - 'Response SLA State' (u_response_sla_state) string field.


                            - 'Trigger Group' (u_trigger_group) reference field to groups.



STEP 2: Create Response SLA definition as below:


                            Screen Shot 2016-04-20 at 10.03.06 AM.png




STEP 3: Create BEFORE UPDATE business rule on incident table as below:


                          Screen Shot 2016-04-20 at 9.57.12 AM.png


                          Code:


function onBefore(current, previous) {



  //This function will be automatically called when this rule is processed.


  current.u_trigger_group = previous.assignment_group;


  current.state = 1;



  var gr = new GlideRecord("task_sla");


  gr.addQuery("task", current.sys_id);


  gr.addQuery("sla", "<sys_id of the SLA Definition record above>");


  gr.addQuery("stage","NOT IN","cancelled,completed");


  gr.query();


  if (gr.next()) {


  current.u_response_sla_state = 'complete';


  } else {


  current.u_response_sla_state = 'create';


  }



}



STEP 4: Create BEFORE INSERT/UPDATE business rule on task_sla table as below:


                              Screen Shot 2016-04-20 at 9.57.36 AM.png


                            Code:


function onBefore(current, previous) {


  //This function will be automatically called when this rule is processed.


  var task_id = current.task;


  var gr = new GlideRecord("incident");


  gr.get(task_id);


  gr.u_response_sla_state = 'create';


  gr.update();


}




This should make it work.


- Hardik Vora


Thanks, Hardik! I know this is an old post. 🙂 Curious: why did you find the Response SLA State field to be necessary? We think it won't be based on the design we've got, but maybe we'll find out it is as we develop it and test it out. Thank you!

nagaraju8
Kilo Guru

Thank you Hardik.



It's works for me.



Thanks,


Nagaraju