Name of month in expense reportPosted: 2012-01-06
Right now I am composing a form in InfoPath for an expense report. I thought that I would share a couple of things with you guys.
I will start of with this post and will probably follow up with one or two more.
In this post I will show you how I accomplished this:
Putting in the name of the month into the form
Ok, first of all you need to create a new data connection to get information from a XML-file.
Copy this code, put it in a Notepad and save it in UTF-8 format as Month.xml:
<?xml version="1.0" encoding="UTF-8"?> <months> <month id="1" name="Januari"/> <month id="2" name="Februari"/> <month id="3" name="Mars"/> <month id="4" name="April"/> <month id="5" name="Maj"/> <month id="6" name="Juni"/> <month id="7" name="Juli"/> <month id="8" name="Augusti"/> <month id="9" name="September"/> <month id="10" name="Oktober"/> <month id="11" name="November"/> <month id="12" name="December"/> </months>
Now create a data connection and choose to get data from another source such as a XML-file. Browse to the file Month.xml and choose to get data whenever the form is opened.
In the Main data source create a new field of the type string called TodaysDate.
Give this field the default value of Today() which will give you todays date.
Create another field of the type string called MonthNrText.
Give this field the default value of substring(TodaysDate, 6, 2) (that is when the date format is like 2012-01-06)
Now let’s create a new field and convert MonthNrText to an integer to take away the leading zeros.
Call this new field MonthNr and give it the value of number(MonthNrText)
Now we have the number of the current month, let’s make one more filed to get the name of this month.
Let’s create a field of the type string and name it MonthName. With this field we will compare the id in the secondary data source against our field MonthNr.
Give this filed the default value of @name[@id = MonthNr], this is how it is done.
Click on the left button insert Field or Group... Choose the secondary data source Month and the field name. Then choose to add a filter to that data by clicking the button Filter data. A new dialog opens up where we choose to Add a new filter.
In the first drop down choose select a field or group and point to id in the secondary data source. In the second drop down choose is equals to and in the final drop down choose select a field or group and point to MonthNr. Here you have all the dialogs:
Ok, so there it is! Now we have the name of the current month.
In the next post I will show you how I made the form keep the name of the valid month, even if it is opened up later and how I made the form editable only until a certain date.