SOLVED

Printing list of custom object fields through Velocity

Go to solution
Victor_Arieta
Level 1

Printing list of custom object fields through Velocity

Hi all, 

I'm trying to create a table where, for the first column, each row is filled with a particular custom object field(credit memo number3, which belongs to the creditmemo3 C.O).  I want to print all entries each contact has for the C.O. I'm using the below code:

 

 

<table border="0">
<tr>
	<td>Credit Memo Number  </td>    <td>     Charity Name</td>
</tr>
#foreach ( $creditMemoNumber3 in $creditMemo3_cList )
<tr>
<td>
$creditMemoNumber3</td>
<td>
${lead.Company}
</td>
#end
</tr>
</table>

 

 

 However, this is the output that I get for the first column. It correctly identified all entries of this field for the contact, but the output format is not what I wanted:

Screenshot 2021-07-01 at 9.13.50 AM.png

 

How can I only display the actual value of the field (in this case, just the numbers, not the name of the field and brackets)?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Printing list of custom object fields through Velocity

In Velocity, your $customObjectList is a list of objects. (An ArrayList of LinkedHashMaps, technically.)

 

When you loop over the list with

#foreach( $loopVar in $customObjectList )

the loop variable $loopVar is set to a new object on each turn of the loop.

 

An object of course has keys and values. So if you just output $loopVar, that uses the standard stringified format for the entire current object

{key=value,key2=value2,key3=value3}

because you haven’t told it you want to output only the value for a certain key.

 

You want to output the key creditMemoNumber3, so that’s

${loopVar.creditMemoNumber3}

 

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Printing list of custom object fields through Velocity

In Velocity, your $customObjectList is a list of objects. (An ArrayList of LinkedHashMaps, technically.)

 

When you loop over the list with

#foreach( $loopVar in $customObjectList )

the loop variable $loopVar is set to a new object on each turn of the loop.

 

An object of course has keys and values. So if you just output $loopVar, that uses the standard stringified format for the entire current object

{key=value,key2=value2,key3=value3}

because you haven’t told it you want to output only the value for a certain key.

 

You want to output the key creditMemoNumber3, so that’s

${loopVar.creditMemoNumber3}

 

Victor_Arieta
Level 1

Re: Printing list of custom object fields through Velocity

Thank you so much!! This is a much more elegant solution (and possibly much more efficient) than what I tried to do, which was:

 

<table border="0">

<tr>

	<td width="175"><b>Credit Reference #</b<  </td>    <td><b>     Charity Name</b></td>

</tr>
#set ( $ordernumber = 0 )
#foreach ( $creditMemoNumber3 in $creditMemo3_cList )



<tr>

<td>

${creditMemo3_cList.get($ordernumber).creditMemoNumber3}</td>

<td>
${lead.Company}
</td>

#set ( $ordernumber = $ordernumber+1 )

#end

</tr>
</table>