how to calculate due date on RITM based on Duration time in workflow

swathib
Mega Contributor

Hi All,

I need to calculate due date on RITM.

1.When request got submitted, the due date as per the schedule will be calculated and will be displayed in the due date field on RITM.

2.Now, once the request got approved, we recalculate the due date field on RITM as per the current time.

ex : Initially when request got submitted, the due date is 02-09 7.45 (2 days delivery time). The request got approved on 01-09 08.00 .Now the due date will be updated as 03-09 08.00 once approved.

I have written Business rule on RITM, after update :

(function executeRule(current, previous /*null when async*/) {

var dueDate = current.due_date.getDisplayValue();

var closedDate = current.closed_at.getDisplayValue();

var deliveryTime = '';

var expTime = new GlideRecord('sc_cat_item');

expTime.addQuery('sys_id', '82f468a00f94360004d6590be1050e7f');

expTime.query();

if(expTime.next())

{

deliveryTime = closedDate + expTime.delivery_time.getGlideObject().getNumericValue();

gs.log('deliveryTime' + deliveryTime,'swathi');

expTime.due_date = deliveryTime.getDisplayValue();

if(closedDate > dueDate){

expTime.made_sla = false;

    }

expTime.update();

}

//gs.log('closed time' + current.closed_at.getDisplayValue(),'swathi');

//gs.log('due_date' + current.due_date.getDisplayValue(), 'swathi');

})(current, previous);

Here the problem is on RITM, 'due date' is not setting... and for the log : gs.log('deliveryTime' + deliveryTime,'swathi'); here task due date is getting...

Can anyone help me where im doing wrong???

3 REPLIES 3

saprem_d
Giga Guru

Hi,



You can add a runscript in your workflow to set the date as per below sample script



var gdt = new GlideDateTime(current.due_date);


current.due_date = gdt.addDays(2);


swathib
Mega Contributor

Hi Dixit,



Thank you for your reply..



But i have to calculate due date for other items as duration in the workflow varies from item to item..



So i thought of Business rule on RITM..


swathib
Mega Contributor

Hi Dixit,



Below is the requirement :



1.When request got submitted, the due date as per the schedule will be calculated and will be displayed in the due date field on RITM.


2.Now, once the request got approved, we recalculate the due date field on RITM as per the current time.


ex : Initially when request got submitted, the due date is 02-09 7.45 (2 days delivery time). The request got approved on 01-09 08.00 .Now the due date will be updated as 03-09 08.00 once approved.


3.This due date on RITM once approved will be updated in the TASK record as well in due date field.We remove the default 14 days period in due date in TASK record.


4.To check if the SLA met or not,we use the field 'Made SLA' on RITM. When RITM gets closed, we calculate the field. If due date greater than closed date, Made SLA will be set as true. Else as false.