SOLVED

Velocity: Programming custom list data

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Programming custom list data


It can't pull information from a custom object?  This feels very limiting.

Velocity absolutely, positively, completely* can pull information from Custom Objects.

 

What’s confusing people is that your Custom Object appears to be called “List” which sends people down a very different road, since they’re thinking about Static or Smart Lists.

 

So let’s rename your Custom Object to something else: “Party Balloon Rental”.

 

Your Party Balloon Rental CO has 2 fields:

  • Rental ID
  • Text3

 

So you want iterate over the list of Party Balloon Rentals to output the value of Text3 when the Rental ID is “Roy-Wambsgans-1234”.

#if( !$PartyBalloonRentals__cList.isEmpty() )
#foreach( $rental in $PartyBalloonRentals__cList )
#if( $rental.RentalID.equals("Roy-Wambsgans-1234") )
${rental.Text3}
#break
#end
#end
#end

 

 

 

 

 

 

 

* Well, 1st-level objects, at least.

Travis_Schwartz
Level 4

Re: Velocity: Programming custom list data

Thank you so much.

 

Yes... we have custom objects that are called custom lists (not sure why... that was the naming convention when I got here, and I came from a different system, so I assumed that was standard.) 

 

by default, our system capitalizes everything. How would I take

${rental.Text3}

and convert that to proper case?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Programming custom list data

Assuming by “proper” you mean first letter uppercase, the rest lowercase:

#if( !$rental.Text3.isEmpty() )
#set( $reCased = $rental.Text3.substring(0,1).toUpperCase() + $rental.Text3.substring(1).toLowerCase() )
#end
Travis_Schwartz
Level 4

Re: Velocity: Programming custom list data

So I was able to follow and substitute much of the token values, but I'm stuck on one part

 

#if( !$customList__cList.isEmpty() )
#foreach( $rental in $customList__cList )
#if( $rental.listID.equals("Referred Members") )
${rental.Text3}
#break
#end
#end
#end

#if( !$rental.Text3.isEmpty() )
#set( $reCased = $rental.Text3.substring(0,1).toUpperCase() + $rental.Text3.substring(1).toLowerCase() )
#end

 

What do I replace the

$rental

 

with?

 

Other than that, did I miss anything?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity: Programming custom list data

This won’t work, you need to set the displayable item inside the loop.

 

#if( !$customList__cList.isEmpty() )
#foreach( $rental in $customList__cList )
#if( $rental.listID.equals("Referred Members") && !$rental.Text3.isEmpty() )
#set( $reCased = $rental.Text3.substring(0,1).toUpperCase() + $rental.Text3.substring(1).toLowerCase() )
#break
#end
#end
#end
${reCased}

 

 

You can rename the loop variable $rental to anything you want. $customList for example.

Travis_Schwartz
Level 4

Re: Velocity: Programming custom list data

Just curious about something on this... let's use the balloon rental example from before:

 

#if( !$PartyBalloonRentals__cList.isEmpty() )
#foreach( $rental in $PartyBalloonRentals__cList )
#if( $rental.RentalID.equals("Roy-Wambsgans-1234") )
${rental.Text3}
#break
#end
#end
#end

 

If there was another field (date1), would you be able to differentiate between custom objects with the same ID?

 

Using the balloon example, could someone have multiple orders that you could identify with something like

#if( $rental.date1.equals(Todays_date) )
Travis_Schwartz
Level 4

Re: Velocity: Programming custom list data

I can do it as a constraint in my smart list... was just curious if velocity could do it as well.

Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity: Programming custom list data

@Travis_Schwartz,

Yes you can do that, and there are different use cases for both the Velocity approach, and the Smart List approach.

 

Smart List

You'd use this if you (e.g.) only wanted people who'd rented balloons today (using your example)

 

Velocity

You'd use this if you wanted to have a different criteria in your smart list (maybe dollarsSpent > $x), but wanted to highlight today's order (maybe bold it, or display it separately or something).

 

Cheers