Creating a Total Amount in Velocity Scripting | Community
Skip to main content
November 9, 2015
Solved

Creating a Total Amount in Velocity Scripting

  • November 9, 2015
  • 1 reply
  • 2050 views

I am trying to create a velocity scripting table that is able to add the total amount of what a person purchased. I am able to pull all the Custom Object data in, but have not successfully added multiple variables. I did find the $math.add( object1, object2 ) function but have been unable to render correctly the $transaction.price if the user has multiple transactions. Has anyone had success adding multiple variables in Velocity Scripting? Current code pasted below.

#set ( $totalprice = 0 )

<table border="1">

  <tr>

  <th>Product Description</th><th>Last Four CC</th><th>Shipping Address</th><th>Shipping Date</th><th>Amount</th>

  </tr>

    #foreach($transaction in $transactions_cList)

  <tr>

  <td>$transaction.description</td>

  <td>$transaction.lastfour</td>

  <td>$transaction.shippingstreetaddress</td>

  <td>$transaction.requiredshipdate</td>

  <td>$transaction.price</td>

  </tr>               

  #end

  <tr>

  <td colspan=5>Total: </td>

  </tr>

</table>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

I don't know where you were trying to do the math. Have you done:

#set( $totalPrice = 0)

#foreach( $transaction in $transaction_cList )

     #set ( $totalPrice = $math.add( $totalPrice, $transaction.price ) )

#end

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 10, 2015

I don't know where you were trying to do the math. Have you done:

#set( $totalPrice = 0)

#foreach( $transaction in $transaction_cList )

     #set ( $totalPrice = $math.add( $totalPrice, $transaction.price ) )

#end

November 10, 2015

Excellent Sanford.

That is exactly what I was missing!