CMS Development

mmcgowan702
Participant

HubL script breaks over formatted number

SOLVE

Hello all,

I am building in email where there is different messaging for recipients based on the amount of points they have in their account. This text is in a module and the module contains the following script;

{% set rfPointTotal = contact.rf_points_total %}
{% if rfPointTotal == 0 %}
<p style="mso-line-height-rule:exactly; font-family:Arial, sans-serif; font-size:15px; color:#333333; word-break:break-word;mso-line-height-rule:exactly; line-height:175%">Since there are no points in your profile, there is nothing more for you to do. <br>Thank you,<br>The RewardFish Team</p>
{% elif rfPointTotal > 0 and rfPointTotal <= 499 %}
<p style="mso-line-height-rule:exactly; font-family:Arial, sans-serif; font-size:15px; color:#333333; word-break:break-word;mso-line-height-rule:exactly; line-height:175%">As of this date you still have <strong>{{ rfPointTotal }} points</strong> left in your account.</p>
{% else %}
<p style="mso-line-height-rule:exactly; font-family:Arial, sans-serif; font-size:15px; color:#333333; word-break:break-word;mso-line-height-rule:exactly; line-height:175%">As of this date you still have <strong>{{ rfPointTotal }} points</strong> left in your account which means you can redeem your points for a gift card. Please log into your account and go to Claim Gift Card to start the process before it's too late.</p>
{% endif %}

The field contact.rf_points_total is a formatted number field. The script works until I come across a member with 1,000 points or more. When I look at the preview of a member who has over 1,000 points I see the following

 

HubL Script Breaking.png

 


When I try to send a test email, it fails.

My conclusion is that it doesn't like the comma in the formatted number field. I did make a copy of this field unformatted, and made a workflow to copy the values from the formatted field to the unformatted field. The script works fine but I do not like this solution as it would be possible to send an email with the wrong value in the unformatted field. Furthermore, the formated field is updated every 10 minutes and is used in other places so I cannot just change the formatted field to an unformatted field.

Is there a way to get my script to work looking only at the formatted field and not breaking?

1 Accepted solution
Jaycee_Lewis
Solution
Community Manager
Community Manager

HubL script breaks over formatted number

SOLVE

Hey, @mmcgowan702 👋 Thanks for the interesting question. It sounds like we need some way to escape that comma when it is used in your module.

 

Looking at the available HubL filters, I found `replace`. Have you looked into this yet? I haven't tested this in a module, but this is a simple example:

{% set rfPointTotal = contact.rf_points_total|replace(",", "")|int %}

HubL Filters — Replace

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

View solution in original post

0 Upvotes
3 Replies 3
Jaycee_Lewis
Solution
Community Manager
Community Manager

HubL script breaks over formatted number

SOLVE

Hey, @mmcgowan702 👋 Thanks for the interesting question. It sounds like we need some way to escape that comma when it is used in your module.

 

Looking at the available HubL filters, I found `replace`. Have you looked into this yet? I haven't tested this in a module, but this is a simple example:

{% set rfPointTotal = contact.rf_points_total|replace(",", "")|int %}

HubL Filters — Replace

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
mmcgowan702
Participant

HubL script breaks over formatted number

SOLVE

Thank you so much Jaycee. I did not know about that particular filter. But that worked!

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

HubL script breaks over formatted number

SOLVE

Amazing! Thanks for asking a great question. Have a fantastic weekend 🙌 — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes