populate drop-down field programmatically - InfoPath Dev
in

InfoPath Dev

populate drop-down field programmatically

Last post 04-14-2005 07:44 PM by webuser. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-09-2005 08:33 AM

    populate drop-down field programmatically

    I see some great posts for binding dropdown fields to secondary data sources such as web services and DB connections.

    What I am trying to do is compute all the pay-periods (15th, 30th) from the current date, 4 months past and 12 months forward. Currently I use a web service to do this. But I feel that this is overkill, if I can do the same thing using Infopath's script capability linked to the document's onLoad() event handler. Here is my code in the web service:

    [WebMethod]
    public String[] getEffectiveDateList()
    {
    String[] dateList = new String[32];
    int currDay;
    int currMonth;
    int currYear;
    DateTime startDate = DateTime.Today.Date.AddMonths(-4).Date;
    for (int count=0; count<32; count++)
    {
    currYear = startDate.Year;
    currMonth = startDate.Month;
    currDay = startDate.Day;
    if (currDay <= 15)
    currDay = 15;
    else
    {
    // Check if February and leap year
    if (currMonth == 2)
    {
    if (DateTime.IsLeapYear(currYear))
    currDay = 28;
    else
    currDay = 27;
    }
    else if (currMonth == 1 || currMonth == 3
    || currMonth == 5 || currMonth == 7
    || currMonth == 8 || currMonth == 10
    || currMonth == 12)
    currDay = 31; // all months with 31 days
    else
    currDay = 30; // all months with 30 days
    }
    //instantiate new date object with calculated pay-period date
    startDate = new DateTime(currYear, currMonth, currDay).Date;
    //add to date list
    dateList[count] = formatDate(startDate);
    startDate = startDate.AddDays(4);
    }
    //return list of dates
    return dateList;
    }

    Can anyone guide me with using this code from within an onLoad() event within InfoPath? Also, even with the web service, somehow the drop down field has the current system date, in addition to the dates returned by the web service. But I do not want this date, as it may or may not be a pay-period date. I know the web service is not returning this date, since it is not returned from an independent invocation of the web method outside of InfoPath.

    I really appreciate any help!

    --Ashwin
  • 03-09-2005 12:50 AM In reply to

    Re: populate drop-down field programmatically

    Hi Ashwin,
    Welcome to the board. InfoPath SP1 supports .NET so you should be able to just create a .NET project for infopath and cut and paste the code in to a method in the FormCode.cs file and call it from OnLoad or from some OnClick handler. Should be pretty easy.

    As for the dates, I don't quite understand why the dropdown has the current system date. I'd have to lok at the form to understand this.

    Good luck,
    Patrick
    Patrick Halstead
    Project Manager at Qdabra
  • 04-14-2005 07:44 PM In reply to

    Re: populate drop-down field programmatically

    Thank you very much, Patrick!
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.