This article continues the discussion in this Repeating Data article, where we looked at capturing repeating data, how to print that data in a list, and also a look at how to filter that list.
Ordinal values
Another common issue with repeating data is the requirement firstly to present a list of the repeating instances and then refer to items within the list by their ordinal values (i.e. first, second, third, etc.), for example Plaintiffs / Defendants:
Adam Andrews First Plaintiff
Brian Bates Second Plaintiff
Carly Chase Third Plaintiff
This is very easy to achieve with the Ordinal() command.
«ForEach(Plaintiff)»
«FirstName» «LastName» «Ordinal(Only,First,Second,Third,Fourth,Fifth and subsequent)» Plaintiff
«End()»
Filter with the ordinal
Suppose you act for some of the Plaintiffs, and you want to list those you act for. This will give you the names of the Plaintiffs you act for:
«ForEach(Plaintiff)»
«FirstName» «LastName» «Ordinal(Only,First,Second,Third,Fourth,Fifth and subsequent)» Plaintiff
«ChooseFromHzRDBList(ActingFor,,Yes,No)»
«CaptureDataElement(ActingFor)»
«End()»
We act for «List(Plaintiff[ActingFor = ‘Yes’],FirstName LastName,!, , and )».
If you rather want to insert a phrase such as “We act for the First and Third Plaintiffs” then it’s slight more complicated, but achievable like this:
«Comment(First set some variables to be used to gather information as we go)»
«SetVr(‘PltPos’,’’)»
«SetVr(‘PltCount’,0)»
«ForEach(Plaintiff)»
«FirstName» «LastName» «Ordinal(Only,First,Second,Third,Fourth,Fifth and subsequent)»
«ChooseFromHzRDBList(ActingFor,,Yes,No)»
«if(ActingFor = ‘Yes’)»
«AppendVr('PltPos',concat(GetListItem(position(),'First,Second,Third,Fourth,Fifth,Sixth,Seventh,Eighth,Ninth,Tenth,',','),'|'))»
«Comment(Take note of the position of the Plaintiff we act for. Append it to a list so we can use in a CommasAndList function)»
«IncrementVr('PltCount')»
«Comment(Add to the count so we can use it for the plural.)»
«End()»
«End()»
«List(Plaintiff[ActingFor = ‘Yes’],FirstName LastName,!, , and )»
We act for the «CommasAndList(GetV(‘PltPos’),'|',',',' and ')» «when(GetV(‘PltCount’) > 1,Plaintiffs,Plaintiff)».