Timesheet - Start date must be a Sunday the week must include 1st or 16th - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

Timesheet - Start date must be a Sunday the week must include 1st or 16th

Last post 05-10-2017 09:25 PM by NathanWynn. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-20-2017 01:41 PM

    Timesheet - Start date must be a Sunday the week must include 1st or 16th

     I am working on a Semi-Monthly Timesheet form and having some issues with the start week.  The form will be filled out for 1-15 and 16- end of month.

    Here are there requirements:

    - Select start of week by using the Date Picker

    - The start date must be a Sunday

    - The week must contain the 1st or 16th. 

    I have a date picker, then I have days of the week below it in a table.  The table is in a section and I want to hide the section until a valid week is entered. People tend to not put the correct date in and I need validation to prevent errors.

    I am having issues getting the rules setup. Just when it looks like it starts to work, I always find a loop hole to bypass the validation. Sometimes I pick a Sunday and it doesn't have a 1 or 16 but it still shows.  Sometimes I pick a valid week and it doesn't show.

    I have setup 7 fields, one for each day of the week, to pull the day of the week from the date picker.  I have rules on each one to determine if it contains a 1 or 16.

    I have another field to determine if the start date is a Sunday.  If it equals 0 its a Sunday. If it doesn't equal 0 then hide the timesheet. 

    Has anyone done something like this before?  Maybe I need to take a new direction?  

     

     

  • 04-28-2017 08:52 AM In reply to

    Re: Timesheet - Start date must be a Sunday the week must include 1st or 16th

     Any chance you could attach a sample form with the work you've already done? Under the Options tab in a reply - I can take a look & maybe give you a hand. :)

    Hilary Stoupa

  • 05-10-2017 09:25 PM In reply to

    Re: Timesheet - Start date must be a Sunday the week must include 1st or 16th

     Hi,

     I don't have the whole solution to your problem, but I have the piece where you can always start the week on Sunday regardless what date was picked from the DatePick or today(). For example: if 05/11/2017 picked, the week starts on Sunday 05/07/2017

    Create Data type Whole Number 'NumericDayOfWeek'

    Create Data type Date 'WeekOf'. Optional default value: today()

    Add a rule named: getNumericDayofWeek with the follow XPath:

     (number(substring(., 9, 2)) + number(number(substring(., 1, 4)) - (floor((14 - number(substring(., 6, 2))) div 12))) + floor(number(number(substring(., 1, 4)) - (floor((14 - number(substring(., 6, 2))) div 12))) div 4) - floor(number(number(substring(., 1, 4)) - (floor((14 - number(substring(., 6, 2))) div 12))) div 100) + floor(number(number(substring(., 1, 4)) - (floor((14 - number(substring(., 6, 2))) div 12))) div 400) + floor((31 * number(number(substring(., 6, 2)) + 12 * (floor((14 - number(substring(., 6, 2))) div 12)) - 2)) div 12)) mod 7

    That simply get the numeric value of 'Day of Week', 0 = Sunday, 1 = Monday... Example: When you run, 'WeekOf' will have today's date of 05/11/2017. With the rule runs automatically you will get a value of 4 (Thursday). To get to the Sunday, you just need to subtract the number value from the date picked. 05/11/2017 - 4 = 05/07/2017

    To achieve that you add a second rule on 'WeekOf'. We name the rule 'IfNotSunday'

    Condition: If 'NumericDayOfWeek' is not 0 then run this rule:xdDate:AddDays(., -../my:NumericDayOfWeek)

    That rule simply subtract itself by the numeric value of Day of Week.

     

    To get to what you need, get the date of the Sunday + 7 or -7 to find out the date range to make sure it contains 1 or 16.

    Hope that helps. Sorry if I was being wordy or not clear. 

     

     

     

     

     

     

Page 1 of 1 (3 items)
Copyright © 2003-2017 Qdabra Software. All rights reserved.
View our Terms of Use.