Need some help with velocity scripting math

bryantchang
Level 2

Need some help with velocity scripting math

learning some velocity scripting and having some issues rendering.

this is what i have.

#if (${topics_cList.get(0).topics_Total} > 0 )

#set( $topic1Percent = $math.div(${topics_cList.get(0).topic1}, ${topics_cList.get(0).topics_Total}) )
#set( $topics2Percent = $math.div(${topics_cList.get(0).topic2}, ${topics_cList.get(0).topics_Total}) )
#set( $topics3Percent = $math.div(${topics_cList.get(0).topic3}, ${topics_cList.get(0).topicsTotal}) )


Percentage of topics 1: $number.number($topics1Percent) %

Percentage of topics 2: $number.number($topics2Percent) %

Percentage of topics 3: $number.number($topics3Percent) %

#end

 

the values are not rendering.

any direction or articles that can help?

 

Tags (1)
3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Need some help with velocity scripting math

This is impossible to answer because you haven't really asked a question!

 

Reverse-engineering someone's reqs from (non-working code) isn't the way to go, and there's almost certainly an XY problem at work here.

 

So please explain (a) your custom object data model and (b) the business requirements.

 

I will say upfront that looking at only the first item in an unsorted list is almost always wrong.

bryantchang
Level 2

Re: Need some help with velocity scripting math

Thanks @SanfordWhiteman .

 

I’ll try my best to rephrase as a question 😉

 

A) Custom Object data model

Custom Object: Topics

Field 1: Total Topics

Field 2: Topic #1

Field 3: Topic #2

Field 4: Topic #3

 

Example Record

Total Topics: 10

Topic #1: 5

Topic #2: 3

Topic #3: 2

 

B) Business Requirement

 

How can I render the percentage value for each topic as so?

Percentage of Topic #1: 50%

Percentage of Topic #2: 30%

Percentage of Topic #3: 20%

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Need some help with velocity scripting math

What happens if there is more than one Custom Object in the list?