Date Calculation - IP2003 - InfoPath Dev
in

InfoPath Dev

Date Calculation - IP2003

Last post 03-31-2008 08:51 AM by Clay Fox. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-21-2008 03:20 AM

    Date Calculation - IP2003

    Hi! Thanks in advance for any help! 

    What I want is a "need by" date ("DateNeededBy") that the user chooses, but that date can not be a weekend nor can it be in the past, today, or tomorrow.

    I've solved the weekend issue creating a "DayOfWeekNumber" variable and setting up a rule in "DateNeededBy" to assign an integer value to the day of the week it happens to be. I then used a validation condition to restrict Saturdays and Sundays. Here's the code if anyone is interested:

    (number(substring(., 9, 2)) + floor(((153 * (number(substring(., 6, 2)) + (12 * floor((14 - number(substring(., 6, 2))) / 12)) - 3)) + 2) / 5) + (365 * (number(substring(., 1, 4)) + 4800 - floor((14 - number(substring(., 6, 2))) / 12))) + floor((number(substring(., 1, 4)) + 4800 - floor((14 - number(substring(., 6, 2))) / 12)) / 4) - 32083) mod 7

    That's working fine. My issue is preventing dates from the past, today, and tomorrow from being entered. Obviously the following validation does not work...

    DateNeededBy | is less than or equal to | today()

    ... because that only does the past and today. And I know that I can not use a simple calculation to add a day. I also know that this would be much easier in IP2007 but upgrading is not an option (we're talking about thousands of users in a corporate environment).

    So I'm down to VB code, which I'm not very familiar with.

    Thanks to Clay Fox's information in this post - http://www.infopathdev.com/forums/p/1192/4234.aspx#4234 - I've been able to calculate tomorrow's date and return it to a variable in the form:

    Sub XDocument_OnLoad(eventObj)
    XDocument.DOM.selectSingleNode("/my:myFields/my:HiddenVariables/my:Tomorrow").text = DateAdd("d",1,date)
    End Sub

    "Tomorrow" is a Text(string) data type.

    My problem now is that InfoPath doesn't see this returned information as a real date. When I set the "Tomorrow" variable as a Date(date) data type, I get nothing in my form.

    It looks to me like the information that the VB code is outputting is not in the format that InfoPath likes to see as a date. I know that there are differences in formats, so my assumption now is that I need some additional code in VB to convert that VBScript date that's being generated in the above code to ISO format that InfoPath needs. Is that correct?

    Now, here's where the help comes in :) ! I have NO idea how I would do that. Can anyone help out?

    Thank you! 

  • 02-21-2008 07:42 AM In reply to

    Re: Date Calculation - IP2003

    Welcome.  There is some great information here!

    You are using vbscript, which I have no idea how to do it in vbscript.  I have done what you are needing many times before in visual basic not vbscript.  Are you confortable with any other languages?  Reason I ask this is that you personally could upgrade to InfoPath 2007 and write code that is backwards compatible with all the users on 2003.  That is my situation, I know vb, but not vb script or jscript.  I got Infopath 2007 for that reason as the slow transition to 2007 is completed here at work.  InfoPath 2007 supports: JScript, VBScript, C# and VB, which can be used in infopath 2003.

     I am sure others will chime in and help you out, but if you need help on the vb(not script) side of it I am more than happy to help you.

    Also thanks for the above work week solution, I have not had a reason to use such event yet, but I know I will in the future.

  • 03-31-2008 05:46 AM In reply to

    Re: Date Calculation - IP2003

    [ BUMP]

    I was wondering if any of you [much smarter than me] folks could take a look at my original post? I would be forever grateful if someone could help me out with this! I don't imagine it's too complicated, but I'm just not familiar enough with the programming to figure this out myself.

    Thanks again to anyone that takes a look at this!

     

  • 03-31-2008 08:51 AM In reply to

    Re: Date Calculation - IP2003

    Hey Tim.

    Why don't you attach you xsn to a post and then I can take a look at it.

    I am guessing your tomorrow filed should be a date format but I can see if i can get it working.

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