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

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!

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

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?

Hi, did you ever manage to solve this?

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
- This article “Python Typecasting: How To Cast a String Into An Integer
I’d also recommend posting in our Developer Forum here, 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 :slightly_smiling_face:
Thanks and have a good day!
Best,
Bérangère

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

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

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
 }
 }