Set default date as output. - InfoPath Dev
in

InfoPath Dev

Set default date as output.

Last post 07-20-2009 03:44 PM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-14-2009 11:32 PM

    Set default date as output.

    Hi,

    My requirement is i have a startdate using datepicker and the end date should be qutomatically filled as {Startdate+3}. I'm not using infopath 2007, so i cannot use addDays function. I'm writing a code like

    This code gets the default date as today and sets the value to current date+3. But i want (startdatevalue+3)

    // Get today's date
        var three_days_from_now = new Date();
        // add three days
        three_days_from_now.setDate(three_days_from_now.getDate() + 3);
       
        // Select the node where the value will be stored
        var targetNode = XDocument.DOM.selectSingleNode("/my:myFields/my:threeDaysFromNow");
       
        // If the node has a nil attribute it needs to be removed
        var nilAttribute = targetNode.getAttributeNode("xsi:nil");
        if(nilAttribute != null)
        {
            targetNode.removeAttributeNode(nilAttribute);
        }
       
        // Store the date in XML format YYYY-MM-DD, adding zeros where necessary
        targetNode.text = three_days_from_now.getFullYear() + '-' +
           zeroPad(three_days_from_now.getMonth() + 1, 2) + '-' + zeroPad(three_days_from_now.getDate(), 2);

    Please suggest.

    Thanks,

    Monisha

    Filed under:
  • 07-20-2009 03:44 PM In reply to

    Re: Set default date as output.

    Hi:

    Is Startdate a field in your form?

    You can get the value with something like:

    var startDate = XDocument.DOM.selectSingleNode("/my:myFields/my:startDate").text;

    With the xpath in bold replaced with your xpath. You'll need to convert the resulting string to a date. I'm not terribly JavaScript-y, but a quick search online suggested you might be able to just pass in the string when you create the new date:

    var start = new Date(startDate)

    Hilary Stoupa

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