One of the interesting features that my team worked on recently was to assign the default value to a text box that was inside a repeating section. That’s easy correct? but we had to display this default value only on the first row. All the subsequent rows created by the user should not display the default values.
This is a well discussed topic on the forums, but one of the annoying part of internet forums is that people tend to show the code which is not always indexed correctly by the search engines. Well, we found the solution to this issue, but the actual solution was buried inside the InfoPath form template.
In this post let’s extract this so that it can help others:
Let’s consider our simple example where we would like to display – “Customer Notes should include their preferred contact name”.
- Let’s start by creating a simple InfoPath template to display the repeating section.
- Navigate to the Field Properties where you would like the default value. (field Notes in our example)
- In order to selectively assign the default value, we can use preceding-sibling XPath expression like below:
substring("Customer Notes should include their preferred contact name", 1, (count(../preceding-sibling::my:Customer) = 0) * 1000)
- The expression above should be entered in the Default value expression box.
- Clicking Verify Formula button will parse the expression and allow you to save the default value.
- Test the InfoPath template
Hopefully in future, people in forums post the actual solution so that we don’t need blog entries like this.