Need Help With a Velocity Script | Community
Skip to main content
Joey_Forcelli1
Level 4
April 19, 2017
Solved

Need Help With a Velocity Script

  • April 19, 2017
  • 1 reply
  • 4829 views

Hey All,

I am trying to put together a simple script to populate an image url based upon a integer value.  I essentially want 1 image if the value is greater than 0 and a default image if the value = 0.  I tried using the below script but it did not work (I have replaced the actual URL with place holder text for demonstration purposes only).

Now, if I set the "highest score" equal to XX, the script will work for leads with a highest score field value = XX.

Once I have this part figured out, I will also need to add an OR statement to check if "highest score 2" > 0

@Sanford Whiteman​ - Hoping you can help me out.

Thanks in advance.

-JF

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

Sorry dude, very new to velocity scripting.

I just tried the following and again it didn't work:

#if( $convert.parseNumber($OpportunityList.get(0).Highest_Score__c) > 0 || $convert.parseNumber($OpportunityList.get(0).Highest_Score_2__c) > 0 )

Appreciate your help with this.


Sounds like you're getting empty strings, not just "0" strings. As long as those fields both exist (even if empty) on every Opportunity object, this works for empty strings and numeric values.

#set( $targetOpp = $OpportunityList[0] )

#foreach ( $oppScoreField in ["Highest_Score__c", "Highest_Score_2__c"] )

#if( $targetOpp[$oppScoreField].isEmpty() )

  #set( $targetOpp[$oppScoreField] = 0 )

#else

  #set( $targetOpp[$oppScoreField] = $convert.parseNumber($targetOpp[$oppScoreField]) )

#end

#end

#if( $targetOpp.Highest_Score__c > 0 || $targetOpp.Highest_Score_2__c > 0 )

One or both fields is > 0.

#else

Neither field is > 0.

#end

Note that I use the square brackets [0] syntax as get() is just OOP chaff.

1 reply

Joey_Forcelli1
Level 4
April 19, 2017

Still trying to troubleshoot this and I am thinking that the field is not being recognized as a integer field.

I set $test = highest score + 1 and the output was [highest score]1

SanfordWhiteman
Level 10
April 19, 2017

#if( $convert.parseNumber($OpportunityList[0].Highest_Score__c) > 0 )

Joey_Forcelli1
Level 4
April 19, 2017

Thank you Sanford.

To turn this into an OR statement, would the logic need to be:

#if( $convert.parseNumber($OpportunityList.get(0).Highest_Score__c) > 0 || $convert.parseNumber(${OpportunityList.get(0).Highest_Score_2__c}) > 0 )