Posted by: Frederik Van Lierde | December 3, 2009

How to sum a field in a repeating table?

This question popuped on a forum, how to sum a field Total within a rpeating Table (So every row has a field Total and we want to total of it)

This is pure 100% InfoPath and I post it as a reference.

Solution
Add a expressionbox (or textbox) outside the Repeating Table and set as default value
sum(my:group1/my:group2/my:Total)

Posted by: Frederik Van Lierde | November 30, 2009

InfoPath Resources example, Cascading dropdowns

Sometimes you need cascading dropdown boxes with predefined values, ofcourse it would be great to add this to a database or link it to a webservice, but it is not always possible.

A solution to this is to use Resources in InfoPath.

Example
The example is use here is coming from Darrin E. (otherwhise I had to invent some case myself)

Combo1 will be filled in with some predefined values (Dairy, Meats, Cans), depending on the value selected in this combo 1, predefined values in combo 2 will be showed.  No external webservice, no database connection, no sharepoint. Ex. when Dairy is selected, combo 2 should contain Lowfat, 2% and whole milk, if meat is selected, beef..pork… should be showed in combo 2 etc.

The problem is not to create cascading dropdown boxes, many people explain this on the internet., but we are going to explain how to do this with resources

1. Create an xml with the data
     <root>
  <group1>
    <combo1>Dairy</combo1>
    <combo2>Lowfat, 2%</combo2>
  </group1>
  <group1>
    <combo1>Dairy</combo1>
    <combo2>whole milk</combo2>
  </group1>
  <group1>
    <combo1>Meats</combo1>
    <combo2>beef</combo2>
  </group1>
  <group1>
    <combo1>Meats</combo1>
    <combo2>Pork</combo2>
  </group1>
  <group1>
    <combo1>Cans</combo1>
    <combo2>large</combo2>
  </group1>
</root>

 

2. Create a new InfoPath template, add 2 combo boxex.  Combo1 and Combo2
3. Click on the menu Tools -> Resource Files
4. Click Add and select the previous created Xml file
5. Click Ok to close the popup box
6. Click on Tools -> Data Connections
7. Click Add
8. Click Receive Data + Next
9. Select Xml Document + Next
10.Click resource Files button and select the previous add resource file
11. Click Next and Select the checkbox “Automatically  retrieve data when the form is opened
12. Click the Finish button
Click the Close button

This is it.  No we have to bind the dropdown boxes to the secondary DataSource.
Using filters in the Combo2 and don’t forget to check “Show only entries with unique display name” for combo 1

 

Posted by: Frederik Van Lierde | November 22, 2009

Weekday name function in InfoPath, without code

InfoPath isn’t strong with dates, but previous post explained already with InfoPath we can do date manipulations.

This blog goes 1 step further, how can we display the name of the day, when selecting a date.

Ex. Select with the datepicker 22-11-2009, thefield should show Sunday
Excel has such a function, InfoPath not.

So this is the way how to do it, out of the box

1. Add the DatePicker field (myDate).
2. Use the previous post to create 3 fields Day, Month and Year
     Link: http://blueinfopath.wordpress.com/2009/11/20/date-field-to-3-textboxes/
3. Add a temp field (to make it more readable).  This temp field can be set visible = false;
 4. Add the following forula to the temp field

(../my:Day + (../my:Year – floor((14 – ../my:Month) div 12)) + floor((../my:Year – floor((14 – ../my:Month) div 12)) div 4) – floor((../my:Year – floor((14 – ../my:Month) div 12)) div 100) + floor((../my:Year – number((14 – ../my:Month) div 12)) div 400) + floor(31 * (../my:Month + (12 * floor((14 – ../my:Month) div 12)) – 2) div 12)) mod 7

5. Add 7 rules to the temp field
      Condition:  temp  is equal to 1
      Action: Set Field WeekDay to Monday
6. Repeat point 5 , 6 times, changing the condition and Action

0 = Sunday
1= Monday
2 = Tuesday

6 = Saturday

Posted by: Frederik Van Lierde | November 20, 2009

Date Field to 3 textboxes

Suppose I have 1 date field and I want to split the day, month and year into 3 numeric textboxes

Field 1: MyDate
Field 2: MyDay
Field 3: MyMonth
Field 4: MyYear

Solution:
1. Set Default Value of Field MyDay to normalize-space(substring-after(substring-after(../my:MyDate, “-”), “-”))
2. Set Default Value of Field MyMonth to normalize-space(substring-before(substring-after(../my:MyDate, “-”), “-”))
3. Set Default Value of Field MyYear to normalize-space(substring-before(../my:MyDate, “-”))
4. Test your InfoPath Form

Explanation
As the date is always saved in the same way in the XML file, we can use substring-before and substriong-after to get the information.

Posted by: Frederik Van Lierde | November 20, 2009

3 dropdown boxes to Date, without code

Suppose I have 3 fields,
Field 1: Day
Field 2: Month
Field 3: Year

We want to concatenate this to a Date Field

Solution:
1. Add a Dropdown Days to the list
2. Add entries from 1 -> 31.  Don’t foget the leading zero for the first 9 days
3. Do the same with the months and years, Be sure that the Value of the entry has the leading zero for the month up to september
     Ex.  March  : Value 03,  Display Name: 3
4. Add a Date Field to the form
5. Set as Default Value concat(../my:year, “-”, ../my:month, “-”, ../my:day)

   When using InfoPath 2003, and you get an error while using the formula, try using ; instead of ,
   concat(../my:year; “-”; ../my:month; “-”;
 ../my:day)

6. Test the form

Explanation:
A date field is saved in the XML as YEAR-MONTH-DAY
The Month and Date has leading zero, zo the lenght of those 2 parts is always 2
By setting the leading zero in the value of the dropdown, we can do it easily out of the box

Posted by: Frederik Van Lierde | November 12, 2009

How to add Save Action to a Button, no code

InfoPath offers to save the file in the menu and in the toolbar.
Sometimes we want to have this functionality related to a button on the form.
In the first view, InfoPath doesn’t has a rule ‘Save Document’ like it has ‘Submit’

Here is the way how to do it, without code:

1. Add a button on the Form
2. Change the Description to Save
3. Go to the Button Properties
4. Click the Rules… button
5.  Click the Add button
6. Change the Name to Save Document
7. Click the Add Action button
8. Select Close the form item from the Action Dropdown list
9. Be sure the checkbox ‘If changes have not been saved, prompt the user to save’ is checked
10. Click all OK button until all popup screens are closed
11. Test the form,

not with preview!
 
IP_ActionSave_CodeLess

 

What will happen
1. When the user fills in the form the first time, and the user clicks on the save button, a Save AS File Dialog will be showed, the user can give a name, select the path etc.
2. When the user re-opens the InfoPath Form, updates the form and click the save button, the file will be saved automatically.

Posted by: Frederik Van Lierde | November 11, 2009

Headers and Data in Print View

A question came up how to print customer details on everypage when printing an InfoPath Form, while on the InfoPath Form w have these details only once.

Follow the next steps to reach this with InfoPath (Tested with 2007)

1. Create a Print View of the InfoPath you like to print
2. Select the newly Created Print View and click View Properties
3. Click on the Print Settings tab
4. Click the Header… button
5. Make up the Header.  To add a field, select Field… in the Insert AutoText Dropdownlist

InfoPathPrintHeaders

Someone can test this in InfoPath 2003?

Posted by: Frederik Van Lierde | November 9, 2009

How to validate correct email address input

Posted by: Frederik Van Lierde | November 3, 2009

DateDifference without Code

As you all know, DateDiff doesn’t exists in InfoPath, so do we have to do when we want to calculate the number of days between 2 given dates?  Alex Pojidaev’s help me out withthis.

What do we need
- 2 date fields in the datasource, startDate, endDate
- 1 text field dayDifference

Step by Step
- Go to the datasource of your InfoPath Form
- Go to the properties of startDate field, and add a rule
            Condition:   endDate is not blank
            Actions:  Set field dayDifference = 0;4096

- Go to the properties of endDate field, and add a rule
            Condition:   startDate is not blank
            Actions:  Set field dayDifference = 0;4096

- Go to the properties of dayDifference field, and add 2 rules
       RULE 1
            Condition:   The Expression : xdDate:AddDays(../my:startDate, substring-before(., “;”)) != ../my:endDate AND
                                     DayDifference contains ;
            Actions:  Set field dayDifference = concat(substring-before(., “;”) + substring-after(., “;”) * ((translate(addDays
                         (startDate, substring-before(., “;”)), “-”, “”) < translate(endDate, “-”, “”)) * 2 – 1), “;”, substring-after(., “;”) / 2)
       (Don’t forget the select the Edit Xpath checkbox)

  RULE 2
             Condition:   DayDifference contains ;
            Actions:  Set field dayDifference = substring-before(., “;”)

Your form is ready, it works also in repeating controls.

DateDiffCodeless

Posted by: Frederik Van Lierde | October 23, 2009

Populate repeating table with selections in 2 Multiple-Selection

How to populate a repeating table (or other control), with values of  2 multiple-selection controls
The most interesting part here is how to add a new record to the repeating node.

Solution
In this case we need to use some C# or VB.net in the code behind

1. Right-Click Multiple-Selection Control 1 and select Programming… -> Changed Event
2. Change the name of the function to PopulateRepeatingControl
3. Enter the following code

‘– Create new record –
CurrentView.ExecuteAction(ActionType.XCollectionInsert,“group9_9″)
‘– fill in newly created record–
Dim root As
XPathNavigator = MainDataSource.CreateNavigator()
root.SelectSingleNode(
“/my:myFields/my:group8/my:group9[last()]/my:field7″, NamespaceManager).SetValue(e.Site.Value)

4. Right-Click Multiple-Selection Control 2 and select Programming… -> Changed Event
5. Delete the function
6. Change the AddHandler min the 
InternalStartup function of both Multiple-Selection Fields to PopulateRepeatingControl

AddHandler

 

EventManager.XmlEvents(“/my:myFields/my:group3/my:field4″).Changed, AddressOf  PopulateRepeatingControl
AddHandler EventManager.XmlEvents(“/my:myFields/my:group4/my:field5″).Changed, AddressOf PopulateRepeatingControl

Explanation
To add a new record to the repeating table, you need to find out the EmlToEdit value of the node
In our example it is group9_9
How to fiind out this value?  Read my post on
http://blueinfopath.wordpress.com/2009/01/19/automatically-add-new-row-to-repeating-control/

By selecting the field, and adding last() as the indexer, you will fillin always the last record of the repeating group.
Don’t forget to change the xpath with the one of your field.

Older Posts »

Categories