- Marketing Nation
- :
- Products
- :
- Product Discussions
- :
- Need some help with velocity scripting math

Your Achievements

Next /

Sign inSign in to Community to gain points, level up, and earn exciting badges like the new Applaud 5 BadgeLearn more!

View All BadgesSign in to view all badges
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-29-2022
10:24 AM

06-29-2022
10:24 AM

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?

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-29-2022
02:48 PM

06-29-2022
02:48 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-29-2022
03:49 PM

06-29-2022
03:49 PM

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%

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-29-2022
05:00 PM

06-29-2022
05:00 PM

Re: Need some help with velocity scripting math

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