Question

I am new to infopath. Can you please guide me how to acheive this scenario.

1) User will select Item Created which is Date Feild.

2) In schedule Interval user will select 1 in first dropdown and Days in 2nd Drop down.

3) In Next Schedule Interval which is date feild should add 1 day.

for ex: In step1 user has selcted 06/08/2013. First drop down 1 and 2nd drop down days Now the date should display as 06/08/2013. Smilarly for months..... Attaching sample screen shot for the same.

https://lh5.googleusercontent.com/-F-h55ksETYA/UbN0NZ891XI/AAAAAAAAC14/Bxn84RpkqtE/w819-h460-no/1.jpg

Était-ce utile?

La solution

This is not easy out of the box. Infopath has a function to add days to a date. Run a rule that only fires when your selector field equals the value "days". Let the rule set the value of the target date with

Rule 1:

addDays(StartDate, IncrementValue)

That one is easy.

It's also easy to increment years, by extracting the year. Internally, the date is stored in the formatt YYYY-MM-DD, so you can extract the year with substring-before(), using the dash as the sepparator. Increment that number, then use the concat() function to combine that new year value with the rest of the start date, i.e. substring-after() using the dash. Create a rule that only fires when the selector field has the value "years" and set the target date with

Rule 2

concat(substring-before(StartDate, "-") + IncrementValue, "-", substring-after(StartDate, "-"))

Where it gets really complicated is the month. Using the same principle of extracting the month, incrementing it and stitching it back into the date is not difficult. The month needs to have a leading zero, though for a valid date entry. That can be achieved by adding 100 to the month and then grabbing only the last two digits. As long as the new date does not cross over into the next year, that approach will work.

Rule 3

concat(substring-before(StartDate, "-"), "-", substring-after(substring-before(substring-after(StartDate, "-"), "-") + 100 + IncrementValue, "1"), "-", substring-after(substring-after(StartDate, "-"), "-"))

If the new date is in the next year, this formula will result in an error. So you will need to create helper fields where you store the month value, and if the calculated month is greater than 12, increment the year and adjust the month value accordingly.

Set the month helper field with this rule:

substring-before(substring-after(StartDate, "-"), "-") + IncrementValue

Then set the target date with this rule, which fires if the month helper is greater than 12:

concat(substring-before(StartDate, "-") + 1, "-", substring-after(MonthHelper - 12 + 100, "1"), "-", substring-after(substring-after(StartDate, "-"), "-"))

If the month helper is less than 13, run rule 3 above

The really difficult problem is that months have different lengths. If you add one month to 2013-01-31 with this technique, the result will be the invalid date string 2013-02-31. Also, leap years need to be taken into account.

Depending on what you want to achieve, you may want to add 30 days for each month, using the addDays() function instead.

If you need a precise month increment technique, you will either need another set of helper cells to evaluate the month/day combination, and make the adjustments, or you would need code that does the date increments more gracefully, but that is not something I can help with.

There are third party tools like Qdabra Software's qRules that provide added functionality for InfoPath forms. qRules includes date functions that can do what you want to without you writing the code.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top