# Converting a string property to an int using custom code in workflow?

**URL:** <https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859>\
**Category:** 💬 RevOps Discussions\
**Tags:** workflows, contacts\
**Created:** [April 21, 2023, 10:12pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859 "2023-04-21T22:12:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MFriberg](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@MFriberg](https://community.hubspot.com/u/MFriberg)\
**Post date:** [April 21, 2023, 10:12pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/1 "2023-04-21T22:12:47Z")

</div>

Hi!  
I’ve recently started deep-diving into what I would consider more advanced parts of HubSpot, and I’ve realized that one crucial property I use in various workflows is stored as a string instead of an integer, which limits how I can use it with list filters/workflow triggers.  
I know that there’s no simple way to convert a string property to an int or float using a workflow that copies the property value, but I was wondering if this could potentially be possible using custom code in a workflow?  
I basically want to copy the contents of property X, which is a string, to property Y, which is an integer, exactly like a Python type conversion:

`int(X)`

Would appreciate any help anyone can offer with this!

---

<div class="post-metadata">

**Author:** ![MiaSrebrnjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/miasrebrnjak/32/10_2.png) [@MiaSrebrnjak](https://community.hubspot.com/u/MiaSrebrnjak)\
**Post date:** [April 24, 2023, 5:30pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/2 "2023-04-24T17:30:14Z")

</div>

Hi @MFriberg,

Thank you for reaching out to the Community!

I wanted to tag in a couple of subject matter experts to see if they can offer any advice:

Hi @Teun, @miljkovicmisa, @ChristinaKay, do you have any tips for @MFriberg? Thank you!

Cheers  
Mia, Community Team

---

<div class="post-metadata">

**Author:** ![MFriberg](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@MFriberg](https://community.hubspot.com/u/MFriberg)\
**Post date:** [May 18, 2023, 9:04pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/3 "2023-05-18T21:04:41Z")

</div>

Hi @MiaSrebrnjak!  
Do you have any other people who might be able to help with this that you could tag to get their eyes on it?

---

<div class="post-metadata">

**Author:** ![AJohnsson](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@AJohnsson](https://community.hubspot.com/u/AJohnsson)\
**Post date:** [September 25, 2023, 12:16pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/4 "2023-09-25T12:16:07Z")

</div>

Hi, did you ever manage to solve this?

---

<div class="post-metadata">

**Author:** ![Berangere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/berangere/32/220784_2.png) [@Berangere](https://community.hubspot.com/u/Berangere)\
**Post date:** [September 25, 2023, 1:15pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/5 "2023-09-25T13:15:10Z")

</div>

Hi @AJohnsson,  
Thank you for reaching out to the Community!  
I found these resources that might help you:  
- The solution from @tmcmillan99 on this post “[Convert url parameter string to integer](https://community.hubspot.com/t5/CMS-Development/Convert-url-parameter-string-to-integer/m-p/443784)”  
- This article “[Python Typecasting: How To Cast a String Into An Integer](https://blog.hubspot.com/website/python-casting-string-int)”  
I’d also recommend [posting in our Developer Forum here](https://community.hubspot.com/t5/HubSpot-Developers/ct-p/developers), since it is custom code, you might be able to get help!  
I’d like to invite a couple of subject matter experts to this conversation @DanielJeal, @ChrisoKlepke and @louischausse do you have any suggestions to help @AJohnsson, please?  
**If anybody else has anything to add and/or share, please feel free to join in the conversation** 🙂  
Thanks and have a good day!  
Best,  
Bérangère

---

<div class="post-metadata">

**Author:** ![DanielJeal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danieljeal/32/93810_2.png) [@DanielJeal](https://community.hubspot.com/u/DanielJeal)\
**Post date:** [September 25, 2023, 2:40pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/6 "2023-09-25T14:40:55Z")

</div>

You can also define the datatype output in the code output return values

---

<div class="post-metadata">

**Author:** ![DanielJeal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/danieljeal/32/93810_2.png) [@DanielJeal](https://community.hubspot.com/u/DanielJeal)\
**Post date:** [September 25, 2023, 3:18pm UTC](https://community.hubspot.com/t/converting-a-string-property-to-an-int-using-custom-code-in-workflow/79859/7 "2023-09-25T15:18:25Z")

</div>

Something like this can do it, also define output as a number and you can use it in a later ‘copy values’ step.

```lia-code-sample
def main(event):
 # Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
 str_id = event["inputFields"]["id"]

 int_id = int(str_id)
 # Return the output data that can be used in later actions in your workflow.
 return {
 "outputFields": {
 "id": int_id
 }
 }

```
