Getting the date through JScript - InfoPath Dev
in

InfoPath Dev

Getting the date through JScript

Last post 08-21-2007 02:43 AM by romaik. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 08-20-2007 04:39 AM

    • romaik
    • Top 500 Contributor
    • Joined on 05-31-2007
    • Paris France
    • Posts 43

    Getting the date through JScript

    Hi every one.

    I am trying to use dates through my form.

    Here is the scenario :
    - If I open a new form, I would like the title bar to display some information, including the date (of the day like 20/08/2007)
    - If I open an already existing form, it displays in the title bar the day the form was last modified.

    I work with InfoPath Sp2 and JScript.
    I can't find it in the InfoPathSDK :s

    thanks for the help

    Regards,
    Romain 

    InfoPath 2003 SP2 User
    Filed under:
  • 08-20-2007 07:22 AM In reply to

    Re: Getting the date through JScript

    hi i would use two fields and a dummy variable for that. The initial date I would get in the OnLoad event of the document like this: function XDocument::OnLoad(eventObj) { var dummy = 0; var date = new Date(); if(dummy == 0) { XDocument.DOM.selectSingleNode("my:myFields/my:newDate").text = date.toDateString(); dummy++; } } Then in the button click event after the updates are done an the form is resaved (you need a custom button for this) I would do a similar thing: var date = new Date(); XDocument.DOM.selectSingleNode("my:myFields/my:DateLastModified").text = date.toDateString(); Does this help ?
    Listen to Motörhead cos they play Rock'n Roll :)
  • 08-20-2007 07:48 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Getting the date through JScript

    Hi,

    You can set the today date and time value in title bar. You can write below the code in OnContextChange event.

    thisXDocument.View.Window.Caption = DateTime.Now.ToString();

    This method will call every time changes made on the form. For avoid this calling function you have to use one global variable.

     Hope this help you.

  • 08-20-2007 08:44 AM In reply to

    • romaik
    • Top 500 Contributor
    • Joined on 05-31-2007
    • Paris France
    • Posts 43

    Re: Getting the date through JScript

    I tried to do this

    var d = new Date();
    XDocument.DOM.selectSingleNode("my:Observer/my:creation").text = d.toDateString();

    in the code of my saving button, but it does not work :s.
    It says : #PCDATA is in a nul content : <{http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-06-18T14:29:33}creation>.

    and the line corresponding to  XDocument.DOM.selectSingleNode("my:Observer/my:creation").text = d.toDateString();

    I decided to put only one element : the date of last modification. here is the scenario.
    - First time, my element is empty and hidden. My button saves and quit, so before saving, I put the Now date into it.
    - Open an existing form (just to read it). Nothing will be modified since he will quit using the red cross.
    - Open an existing form to modify it. Since he is gonna save through my button, the Now date will be put inside my element.

     

    What I wanted to do something like this (for the scenario of the existing form) but it does not work at all :

    var uri = XDocument.URI;
    var file = new File(u);
    XDocument.View.Window.Caption = file.DateLastModified;

    Any idea on those two points ?
     

    InfoPath 2003 SP2 User
  • 08-20-2007 11:41 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Getting the date through JScript

    Hi,

    You have to write the below code in onContextChange event:

    public void OnContextChange(DocContextChangeEvent e)

    {

    //Get the modified date. var modifiedDate = XDocument.DOM.selectSingleNode("my:Observer/my:creation").text;

    if(modifiedDate.length != 0)

       {

        XDocument.View.Window.Caption = modifiedDate;

       }

    }

     For every time saving the form you have to set the modified date to above field(my:creation).

    Hope this Help you

  • 08-21-2007 02:43 AM In reply to

    • romaik
    • Top 500 Contributor
    • Joined on 05-31-2007
    • Paris France
    • Posts 43

    Re: Getting the date through JScript

    The only way I could sort out this problem was using a new entry in the primary data source.
    Now it works great. Too bad InfoPath cannot get the file that he is opening, this would have solve the problem :s

     Thank you both for the help
     

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