# HUBL: converting string to int

**URL:** <https://community.hubspot.com/t/hubl-converting-string-to-int/134556>\
**Category:** Email Marketing Tool\
**Tags:** marketing-email\
**Created:** [June 16, 2025, 10:43am UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556 "2025-06-16T10:43:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JWright76](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@JWright76](https://community.hubspot.com/u/JWright76)\
**Post date:** [June 16, 2025, 10:43am UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/1 "2025-06-16T10:43:40Z")

</div>

Help! I’m trying to convert a string to an int but not having any joy:  
This is what I’m doing:  
{% set event\_id = ‘{{ p145771107\_hapily\_registrant.event\_id |int}}’ %}  
Where event\_id is a single line text field on the event registrant object. But it returns zero:  
If I hardcode an example event id value it works e.g.  
{% set event\_id = “167207073994”|int %}  
I’ve tried trimming etc. but it doesn’t seem to want to convert it into an int

---

<div class="post-metadata">

**Author:** ![ArisudanTiwari](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/arisudantiwari/32/93919_2.png) [@ArisudanTiwari](https://community.hubspot.com/u/ArisudanTiwari)\
**Post date:** [June 16, 2025, 11:23am UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/2 "2025-06-16T11:23:46Z")

</div>

Hi @JWright76 ,

The issue you’re facing with converting a string to an integer in HubL is a common one, especially when working with dynamic data like a custom object’s event\_id.

The main problem is the use of quotes and {{ }} inside your {% set %} statement. Those are only needed when you’re outputting values, not when you’re assigning them.

> **[HubL filters - HubSpot docs](https://developers.hubspot.com/docs/cms/reference/hubl/filters)**
>
> HubL filter list and examples for HubSpot CMS developers.

Instead of {% set event\_id = ‘{{ p145771107\_hapily\_registrant.event\_id |int }}’ %}, use  
{% set event\_id = p145771107\_hapily\_registrant.event\_id |int %}

This will correctly apply the |int filter and store the result as an integer.

---

<div class="post-metadata">

**Author:** ![JWright76](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@JWright76](https://community.hubspot.com/u/JWright76)\
**Post date:** [June 16, 2025, 11:28am UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/3 "2025-06-16T11:28:33Z")

</div>

Thanks for getting back @ArisudanTiwari . I did actually try that but still no joy, although having output the length of the strings it seems there’s something going on with the event\_id field

{% set event\_id = p145771107\_hapily\_registrant.event\_id | string | trim %}  
{% set event\_id\_text = “167207073994” | string | trim %}

event\_id length: {{ event\_id | length }}\<br\>  
event\_id\_text length: {{ event\_id\_text | length }}\<br\>

EventId: {{ event\_id }} \<br\>  
EventId (text): {{ event\_id\_text }} \<br\>  
Outputs:  
event\_id length: 41  
event\_id\_text length: 12  
EventId: 167207073994  
EventId (text): 167207073994  
so no idea what the extra chars are in the event\_id field

---

<div class="post-metadata">

**Author:** ![JWright76](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@JWright76](https://community.hubspot.com/u/JWright76)\
**Post date:** [July 10, 2025, 12:38pm UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/4 "2025-07-10T12:38:19Z")

</div>

Thanks for all responses on this. I actually got this working by simplly enabling programmable email for the module! It’s a bit odd the way it failed without this enabled, a ‘you’re trying to using functions that require programmable email’ message might be nice

---

<div class="post-metadata">

**Author:** ![ArisudanTiwari](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/arisudantiwari/32/93919_2.png) [@ArisudanTiwari](https://community.hubspot.com/u/ArisudanTiwari)\
**Post date:** [June 16, 2025, 1:42pm UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/5 "2025-06-16T13:42:46Z")

</div>

Hi @JWright76 ,  
Try the this code -

{% set event\_id = p145771107\_hapily\_registrant.event\_id | string | trim %}  
{% set event\_id\_clean = event\_id | replace(‘[^0-9]’, ‘’, ‘g’) %}  
{% set event\_id\_int = event\_id\_clean | int %}

Cleaned EventId: {{ event\_id\_clean }}\<br\>  
As Integer: {{ event\_id\_int }}

---

<div class="post-metadata">

**Author:** ![JWright76](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@JWright76](https://community.hubspot.com/u/JWright76)\
**Post date:** [June 16, 2025, 1:54pm UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/6 "2025-06-16T13:54:24Z")

</div>

Thanks, but it’s giving me a cannot resolve property error in Design Manager.  
I’m actually convinced that despite me using  
{% set event\_id = p145771107\_hapily\_registrant.event\_id %}  
It’s still only setting event\_id to be the literal value of: “{{p145771107\_hapily\_registrant.event\_id}}”  
as this is actually 41 chars long. I’ve tried using render filter also, but with no luck. So now I’m probably going to use a different approach now and just stamp the fields I need onto the event registration record, I’d prefer to be able to pull it straight from the event record, but think when you start having to do things like trim and regex replace the code becomes a bit prone to breaking. I will investigate further when have more time.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [June 23, 2025, 5:52pm UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/7 "2025-06-23T17:52:31Z")

</div>

Hey, @JWright76, thanks for the fantastic question. I think you’ve gotten yourself pretty dang close here.

What about, instead of trying to assign the property directly, create it as a string first and **then** using the render filter to process it? This explicitly tells HubL to treat the contents of the string as HubL and to execute it.

```lia-code-sample
{% set event_id_string_token = "{{ p145771107_hapily_registrant.event_id }}" %}

{% set rendered_event_id = event_id_string_token|render|trim %}

{% set event_id_int = rendered_event_id|int %}

```

If that fails, at least we’ll have another clue to work with. Have fun testing! — Jaycee

---

<div class="post-metadata">

**Author:** ![AGupta58](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/agupta58/32/226427_2.png) [@AGupta58](https://community.hubspot.com/u/AGupta58)\
**Post date:** [June 17, 2025, 4:18am UTC](https://community.hubspot.com/t/hubl-converting-string-to-int/134556/8 "2025-06-17T04:18:59Z")

</div>

###### 

**HUBL: converting string to int**

Hi @JWright76  
The issue is with how you’re using quotes and `{{ }}` in your `{% set %}` statement. In HubL:

- `{{ }}` is used to **output** a value to the page.
- `{% %}` is used to **assign** or process logic.

So, this line is **incorrect** :  
{% set event\_id = ‘{{ p145771107\_hapily\_registrant.event\_id |int }}’ %}

This returns `0` because you’re actually converting the **string literal** `'{{ p145771107_hapily_registrant.event_id |int }}'` — not the real value.

### ✅ Use this instead:

_{% set event\_id = p145771107\_hapily\_registrant.event\_id | int %}_

This properly fetches the `event_id`, converts it to an integer using the `|int` filter, and assigns it to `event_id`.

* * *

Let me know if you want to debug specific values or check if the field is null or empty before converting.

**Ankita Gupta  
HubSpot Advisor**  
[![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/c/0ce75e172fc9c2a6cdd5c417354adc372de62a87.png)](https://www.grazitti.com/services/marketing/platforms/hubspot?utm_source=Arisudan_Tiwari_Hubspot_Community&utm_medium=email&utm_content=hubspot_service)
