Skip to main content
Level 2
June 29, 2022
質問

Need some help with velocity scripting math

  • June 29, 2022
  • 3 の返信
  • 1633 ビュー

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?

 

このトピックへの返信は締め切られました。

3 の返信

SanfordWhiteman
Level 10
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.

bryantchang作成者
Level 2
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
Level 10
June 30, 2022

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