Pages

Thursday 1 November 2012

How to ensure the field value is the same in a repeating section in an InfoPath form hosted in SharePoint 2010 Forms library

Scenario:
Consider this: You have a information request form at a school. When someone (who is an authorised requester) requests information for a student. The admin staff use this form to record the information sent to the requester for legal reasons. The admin staff are allowed to add multiple students for the same request however, the students need to be from the same school.

When the admin staff login, their details are populated automatically from GetUserProfileByName web service.


`Figure 1

The form has a repeating control as seen in Figure 2 (People Picker Control + Label (Field Name is ChildSchool)) in an InfoPath form which is published to a Form Library in SharePoint 2010


Figure 2
Problem:
Since it is a repeating section, you cannot control or know the number of instances of the control. A user can add many by clicking the insert link.

Solution:
Add another control (text) to form called AllSchoolNames, it does not have to be visible on the form it is just used to calculate the total number of schools
Figure 3

Click properties of the AllSchoolNames field and add this to the Value field under Default Value Section
eval(eval(NameOfChilds, 'concat(../my:childSchool, substring(";", 1, string-length(../my:childSchool)))'), "..")




Click on "fx" and click on "Edit XPath (advanced)" - Ensure your values look similar to this:

xdMath:Eval(xdMath:Eval(../my:NameOfChild/my:NameOfChilds, 'concat(../my:childSchool, substring(";", 1, string-length(../my:childSchool)))'), "..")

This will return either o (false) or 1 (true)

That's it. Based on the return value you can include Rules to perform an action.

Hope it helps:
References:

http://www.infopathdev.com/forums/p/7124/75545.aspx

No comments:

Post a Comment