Need some help with velocity scripting math | Community
Skip to main content
New Participant
June 29, 2022
Question

Need some help with velocity scripting math

  • June 29, 2022
  • 1 reply
  • 1613 views

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?

 

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

1 reply

SanfordWhiteman
New Participant
June 29, 2022

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.

New Participant
June 29, 2022

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
New Participant
June 30, 2022

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