RepeaterPosition – XpressDox

Consider the commands OnExitSet and OnEnterSet. These commands are only executed during the lifetime of the interview, and also contain conditions which need to be evaluated when the user navigates through the interview.

Also consider the case where you would like certain actions to take place depending on the position of the current repeater. For instance, you might want to issue a warning as soon as the user adds a new Child repeater into the interview, but only if the new Child is not the first one. This might look like this:

«ForEach(Child)»
Name: «Name»
«Footing(Name,                        )»

«OnEnterSet(Name,Name,FootingText,(position() > 2),'You have exceeded the recommended number of children','',EvenWhenNotEmpty)»

«End()»

On the face of it, this would put the “You have exceeded…” message into the footing of data element Name when the position of the new Child repeater is greater than 2.

Unfortunately, the position() function does not operate until the document is being assembled, as it requires the ForEach to be active. There is, however, the XpressDox function RepeaterPosition() which will do what is required, as follows:

«ForEach(Child)»
Name: «Name»
«Footing(Name,                        )»
«OnEnterSet(Name,Name,FootingText,(RepeaterPosition(Child) > 2),'You have exceeded the recommended number of children','',EvenWhenNotEmpty)»
«End()»

A further feature of this function is easier to describe in the context of an example:

«ForEach(Child)»

Name: «Name»
«ForEach(Pet)»
Pet’s Name: «PetName»
«Footing(PetName,                        )»

«OnEnterSet(PetName,PetName,FootingText,(RepeaterPosition(../Child) > 1),'Only the first Child may have a pet!','',EvenWhenNotEmpty)»

«End(Pets)»
«End(Children)»

Here is an example of how to show the position in the interview:

«SetRepeaterQualifier(Child,No. <RepeaterPosition(Child)> <Name>)»

Try it inside one of the above examples to see the effect.