Calculate Due-Date with client-script

wac
Kilo Contributor

Hello again,

I am trying to set a due-Date based on the Priority:
1 = 4 hours
2 = 8 hours
3 = 16 hours
4 = 32 hours
5 = 1 week

the tricky part with 2, 3 and 4 is, that the buissiness hours should be taken into consideration.

Since the user should be able to correct the "default" settings I'd like to implement that feature with a clientscript wich gets called everytime the priority-fild changes.

Has anyone an idea on where to start? Or maybe someone has a differnt idea on implementing such a feature?

Thanks a lot,
Chris.

5 REPLIES 5

gaidem
ServiceNow Employee
ServiceNow Employee

I would suggest you look at SLM: http://wiki.service-now.com/index.php?title=Service_Level_Agreements

If that doesn't work I would use a business rule instead. You may then also need to create a table listing the priorities and other information to calculate the due date. Think of this as a translation table. You business rule will run on insert or update and you may want the condition to contain current.priority.changes() so the rule won't run all the time.


Jay_Ford
Kilo Guru

The way I handled it in my instance is to use a combination of a business rule and incident SLA's.

I first setup SLA's for incident resolution for each of the different priorities we have. In these SLA's you can define a business hours calendar for the ones that require it. In our case a 1 is 4 hours without business hours consideration, and all the rest we use business hours.

I then setup a very late running BR to lookup the planned end date of the active resolution SLA and set the due date of the incident to that date when the Priority changes. This BR has to run after all the SLA business rules run, otherwise it will pick up the wrong SLA when it's changed.

The link provided by the previous poster will help you setup the SLA's. For the business rule, below is mine, it may take a bit of modification for your purposes. It just looks for an active SLA with 'Resolution' in the name (all of my resolution SLA's have Resolution in the name) for the incident in question. Then sets the due date of the incident to the planned end date of the SLA.



setDueDate();

function setDueDate() {

var taskSysID = current.sys_id;
var dueD = '';
var taskSLA = new GlideRecord('task_sla');
taskSLA.addQuery('task', taskSysID);
taskSLA.addQuery('sla.nameCONTAINSResolution');
taskSLA.addQuery('active', 'true');
taskSLA.orderByDesc('sys_created_on');
taskSLA.query();

while (taskSLA.next()) {
gs.log('The task sla name is ' + taskSLA.sla.name);
if(taskSLA.planned_end_time != current.due_date){
current.due_date = taskSLA.planned_end_time;
current.setWorkflow(false);
current.update();
}
}
}


Hi Jay, I looked at it from the other way.   I am running a Business Rule on the task_sla table and updating the task_sla parent task:



function onAfter(current, previous) {


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


      setDueDate();


      //function locates the task related to the SLA (1 record) and updates the Task due date


      function setDueDate(){


              var gr = new GlideRecord('task');


              gr.get(current.task);


              //update the due date from the task_sla planned_end_date


              gr.due_date = current.planned_end_time;


              gr.setWorkflow(false);


              gr.update();


      }


}



Darren


Hey Jay,



The business rule works well but I am facing one issue. What happens is, if I change priority from P1 to P3 then the due date is taken of P1 (ideally should take that of P3). Now from P3 to P2 so due date is taken that of P3 (ideally should take that of P2). So it is taking a due date of its earlier priority. Also, modified the order value for the rule so as to run after but still the issue persists.