Date and Time Onload - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Date and Time Onload

Last post 12-04-2009 06:43 AM by WonderLaura. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 12-01-2009 09:48 AM

    • Gannje
    • Not Ranked
    • Joined on 11-18-2009
    • Posts 6

    Date and Time Onload

    I have a form that has to auto fill fields, Date and RFQ ( which is a number built from the current date and time ). On the creation of a new form, these both work perfectly. My problem is after a form has been filled and saved to Share Point, when it is re-opened, the feilds are updated to the current date and time again, which I do not want. I have written a couple of Javascript IF statements that check to see if the fields are empty before filling with the current D&T, and the code works perfectly when placed in an OnClick event. But when I move the code to the OnLoad event, the fields are updated whether it's a new form or one that already contains data. I think the form is running the script before the fields can be updated with the data. Is there a way to use a Javascript delay with the Infopath OnLoad function, or is there something else I could be doing? Any help would be very appreciated. Below is my code for the Date field (the other is too long to post, and if I can get this one to work, they should both work anyway).

     function XDocument::OnLoad(eventObj)
    {
     // Write your code here
    if (XDocument.DOM.selectSingleNode("/my:myFields/my:header/my:Date").text != " ")
      {
       var ldate = new Date();
       XDocument.DOM.selectSingleNode("/my:myFields/my:header/my:Date").text = ldate.toLocaleDateString();
      }
    }

     

    Thanks Again,

  • 12-01-2009 06:57 PM In reply to

    Remove the calculations from the default value and create an Open Rule with a condition that checks to see if the field is blank or not and if so sets the value based on the function/calculation.

    Patrick Halstead
    Project Manager at Qdabra
  • 12-02-2009 08:11 AM In reply to

    • Gannje
    • Not Ranked
    • Joined on 11-18-2009
    • Posts 6

     Thank you. That worked great for the Date. Is there a way to do that with code? My other field is a number built from the current date and time to create the following format... 20091202-110931. Unfortunately there is no function or stock format for this in IP, that I have found. But I need it to do the same thing as the Date field, create a new number only if there is nothing in that field already. Thanks again.

  • 12-02-2009 08:13 AM In reply to

     Isn't that just the datetime with the hyphens and colons removed, and the T replaced with a hyphen?

     You should be able to construct this with XPath's substring() functions.  No code needed.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-02-2009 08:29 AM In reply to

    • Gannje
    • Not Ranked
    • Joined on 11-18-2009
    • Posts 6

     That's exactly what it is... But I'm very new to IP, I didn't know about the substring() functions. Let me look into that, thanks. I might have to ask for some direction with this, but I'll take a stab at it first.

  • 12-02-2009 08:56 AM In reply to

    • Gannje
    • Not Ranked
    • Joined on 11-18-2009
    • Posts 6

     Patrick and Jimmy, you guys are awesome... The form is working just the way I need it. Thanks to both of you.

  • 12-04-2009 06:43 AM In reply to

    Custom code is really not necessary for this functionality.  On the Date/Time field, if you'ld like the date to NOT change the next time the form is opened, there's a simple checkbox.

    On the properties for the field, UNcheck "Update this value when the result of the formula is recalculated"

     

    Laura Rogers
    http://sharepoint911.com/blogs/laura

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