Calculate problem task duration

chetanpanch
Tera Contributor

I am using below business rule script to calculate the problem task duration. It is working fine in my PDI but it is not working in Customer Instances.

Any suggestions would be very helpful.

Thanks in Advance.

//Script

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

    current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
current.closed_at = gs.nowDateTime();
//current.business_duration = gs.calDateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
//current.business_stc = gs.calDateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);
current.calendar_duration = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
current.calendar_stc = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);
}
})(current, previous);

 

4 REPLIES 4

aizawaken
Tera Guru

hi @chetanpanch ,
Just let me clarify 2 points.
1. Which line in your scripts, isn't it running?
2. Is your PDI's time zone setting same as your customer's instance?

And also, I hope this topic would help you to solve,,,

1. I added some logs in to script to check whether business rule is getting executed or not so it is getting executed but I am not getting any value in the duration field. 
2.My PDI time zone is IST and customer's time zone is EST.

I tried matching the PDI and VDI time zone but still the issue is same its working in PDI but not in VDI.

aizawaken
Tera Guru

hi @chetanpanch , thanks for your reply.

 

So, time zone is not related to your problem,,, 

Then,  how about checking the community topic I wrote?

And also, I hope this topic would help you to solve,,,
This topic says that 1st date param should be greater than the 2nd date parameter in order to get a correct result.
According to your code, 2nd param is always greater than the 1st date param, I guess.
If you try as below, what will happen,,,?

------ exchange 1st param and 2nd param -----
current.calendar_duration = gs.dateDiff(current.closed_at.getDisplayValue(),current.opened_at.getDisplayValue(),false);
-------------------------------------------------------

 

But,,, in your PDI, current code causes no error, you said,,, strange,,,