Skip to main content
Level 2
Jun 29, 2022 5:24 PM UTC
Question

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?

 

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

3 replies

SanfordWhiteman
User Group Leader
User Group Leader
Jun 29, 2022 9:48 PM UTC

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.

Translate
Level 2
Jun 29, 2022 10:49 PM UTC

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%

 

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Jun 30, 2022 12:00 AM UTC

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

Translate