Wednesday, April 6, 2016

Developer: Calculating DueDate excluding weekends

Very often while working with Cases and Entitlements you run into situation where you need to calculate the DueDate excluding weekends and in some cases Holidays are loaded in the system and your DueDate is to factor in Holidays as well.

For the purpose of this post, I am just considering that the requirement is to calculate DueDate excluding weekends.

Solutions

Identify the field which will act as the Start date from which to calculate the Due date.
Identify the field which will store the NumofDays that are to be be added to Start Date

Add a formula field to your object as follows:

CASE( 
MOD(DATEVALUE(SlaStartDate) - DATE(1900, 1, 7), 7), 
0, (DATEVALUE(SlaStartDate )) + SLANumOfDays__c + FLOOR((SLANumOfDays__c-1)/5)*2, 
1, (DATEVALUE(SlaStartDate )) + SLANumOfDays__c + FLOOR((SLANumOfDays__c)/5)*2, 
2, (DATEVALUE(SlaStartDate )) + SLANumOfDays__c + FLOOR((SLANumOfDays__c+1)/5)*2, 
3, (DATEVALUE(SlaStartDate )) + SLANumOfDays__c + FLOOR((SLANumOfDays__c+2)/5)*2, 
4, (DATEVALUE(SlaStartDate )) + SLANumOfDays__c + FLOOR((SLANumOfDays__c+3)/5)*2, 
5, (DATEVALUE(SlaStartDate )) + SLANumOfDays__c + CEILING((SLANumOfDays__c)/5)*2, 
6, (DATEVALUE(SlaStartDate )) - IF(SLANumOfDays__c>0,1,0) + SLANumOfDays__c + CEILING((SLANumOfDays__c)/5)*2, 
null)

Display the field on the UI, it will display the DueDate excluding weekends but does not factor in Holidays.

To factor in Holidays definitely require coding and will be addressed in another post.

No comments:

Post a Comment