SOLVED

Velocity script retrieving fields value from last opportunity

Go to solution
Highlighted

Velocity script retrieving fields value from last opportunity

Hey guys!

I've been trying this Velocity script inside a token in order to retrieve fields value contained in the last opportunity attached to a lead:

$!OpportunityList.get(OpportunityList.size() - 1).fieldName

But an error occurred while rendering the email (error is happening when encountering " - 1").

Any thoughts about this?

Thanks a lot

Keyvan

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Velocity script retrieving fields value from last opportunity

Ok I fixed it with this one:

#set($listSize = $OpportunityList.size() - 1)

$!OpportunityList.get($listSize).fieldName

The only case where it won't be working is when OpportunityList is empty (but this can't happen in my case).

Hope this helps!

View solution in original post

2 REPLIES 2
Highlighted

Re: Velocity script retrieving fields value from last opportunity

Ok I fixed it with this one:

#set($listSize = $OpportunityList.size() - 1)

$!OpportunityList.get($listSize).fieldName

The only case where it won't be working is when OpportunityList is empty (but this can't happen in my case).

Hope this helps!

View solution in original post

Highlighted
Level 10 - Community Moderator

Re: Velocity script retrieving fields value from last opportunity

Hi Keyvan,

Math operators are technically unsupported by the VTL parser (which is why you'll see something like $variable-1 break while $variable - 1 with spaces works in certain cases). It's kind of dumb luck whether the syntax will make its way to the Java level intact.

So you should use the $math object instead. This is the last item in the ArrayList:

$Object__clist[$math.sub($Object__clist.size(),1)].fieldName