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