Open the form template in InfoPath 2013 Designer. Make sure you already have the date field created.
View the Form Load Rules pane. To display this pane go to the Data ribbon and at the far right you will see a button called "Form Load".
We can set a date field by default when the form loads to a business day in the future using three form load rules.
Rule 1 - Detect Sunday
This rule needs two condition criteria. First we don't want to overwrite an existing value and second is to detect of the date we want, 7 days from today, lands on a Sunday. If that condition is met then we need to set the date field to 5 days from today so the resulting day is the next Friday.To detect if 7 days from today is a Sunday you will enter this XPath expression in the condition field.
(number(substring(xdDate:AddDays(xdDate:Today(), 7), 9, 2)) + number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) + floor(number(number(substring(xdDate:AddDays(xdDate:Today(), 5), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) div 4) - floor(number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) div 100) + floor(number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) div 400) + floor(31 * number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2)) + 12 * floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12) - 2) div 12)) mod 7 = 0The rule's condition looks like this:
The rule's action looks like this:
Rule 2 - Detect Saturday
This rule is identical to the first rule except that the XPath condition compares the result to 6, representing Saturday, instead of 0 representing Sunday. The action differs by adding 6 days to today so the result is the next Friday.(number(substring(xdDate:AddDays(xdDate:Today(), 7), 9, 2)) + number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) + floor(number(number(substring(xdDate:AddDays(xdDate:Today(), 5), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) div 4) - floor(number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) div 100) + floor(number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 1, 4)) - floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12)) div 400) + floor(31 * number(number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2)) + 12 * floor((14 - number(substring(xdDate:AddDays(xdDate:Today(), 7), 6, 2))) div 12) - 2) div 12)) mod 7 = 6
Rule 3 - Set Due Date one week ahead
The final rule has one condition like the previous two of making sure the date field is empty, meaning the field didn't have a value when it was loaded and the previous rules didn't set it. It doesn't need to check if the new date lands on a week end because both those scenarios have already been addressed with the first two rules. All this rule needs to do is set the date field to 7 days from today which is the equivalent of adding 5 business days to today. This looks like the following:
No comments:
Post a Comment