Page 1 of 1

Iterating through {{Order.Buyers.People}}

Posted: Thu Aug 27, 2020 2:38 pm
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!

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

Posted: Fri Aug 28, 2020 10:23 am
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}}>)>

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

Posted: Mon Aug 31, 2020 6:04 pm
by kylecrosland
Thanks, Bob! :D