Iterating through {{Order.Buyers.People}}

Discussions related to ReadyDoc development.
Post Reply
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Iterating through {{Order.Buyers.People}}

Post by kylecrosland »

Hi everybody,

I'm trying to concatenate a list of names and titles for all people involved with an organization who is the buyer/borrower, but I can't seem to get it to iterate through the {{Order.Buyers.People}} collection in the ReadyDoc. I can do it in the Formula Editor, but not here.

Code: Select all

<COMMENT> PC {{Order.Buyers}} </COMMENT>
<VAR $Names (“”)>
<VAR $Counter (0)>
<VAR $PeopleCount (0)>
<FOREACH ({{.People}})>
	<VAR $PeopleCount ({{$PeopleCount}} + 1)>
</FOREACH>
<FOREACH ({{.People}})>
	<VAR $Counter ({{$Counter}} + 1)>
	<IF ({{$Counter}} = 1)>
		<VAR $Names ({{.FullName}} + “, its “ + {{.Title}})>
	<ELSE>
		<IF ({{$Counter}} = {{$PeopleCount}})>
			<VAR $Names ({{$Names}} + “; and “ +  {{.FullName}} + “, its “ + {{.Title}})>
		<ELSE>
			<VAR $Names ({{$Names}} + “; “ +  {{.FullName}} + “, its “ + {{.Title}})>
		</IF>
	</IF>
</FOREACH>
The purpose of this code is to construct the $Names variable, and to be able to use it elsewhere in the document. I try to construct it by looping through the {{Order.Buyers.People}} collection, but when I check the values of $Counter and $PeopleCount, they're both returning zero. What am I doing wrong? Thanks!
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Iterating through {{Order.Buyers.People}}

Post by BobRichards »

Here's what one of our documents developers had to say...

The coding they provided is mostly correct, other than a few small syntax errors. The SPML iteration FOREACH should be coded without parentheses. (Removed parenthesis from line 2 and 5, below.)

Code: Select all

<VAR $PeopleCount (0)>
<FOREACH {{.People}}>
    <VAR $PeopleCount ({{$PeopleCount}} + 1)>
</FOREACH>
<FOREACH {{.People}}>
After removing these parentheses, the coding should work fine, but please let me know if any further assistance is needed.

One bonus tip -- the $PeopleCount variable used in the FOREACH shown below...

Code: Select all

<VAR $PeopleCount (0)>
<FOREACH {{.People}}>
    <VAR $PeopleCount ({{$PeopleCount}} + 1)>
</FOREACH>
...can also be compiled using our <COUNT> command -- which has syntax similar to our FOREACH (no parentheses, as shown below):

Code: Select all

    <VAR $PeopleCount (<COUNT {{.People}}>)>
Bob Richards, Senior Software Developer, SoftPro
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Iterating through {{Order.Buyers.People}}

Post by kylecrosland »

Thanks, Bob! :D
Post Reply