💬 RevOps Discussions

MFriberg
Participant

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

SOLVE

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!

0 Upvotes
1 Accepted solution
DanielJeal
Solution
Participant

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

SOLVE

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

 

View solution in original post

6 Replies 6
DanielJeal
Solution
Participant

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

SOLVE

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

 

DanielJeal
Participant

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

SOLVE

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

AJohnsson
Participant

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

SOLVE

Hi, did you ever manage to solve this?

0 Upvotes
BérangèreL
Community Manager
Community Manager

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

SOLVE

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 🙂

Thanks and have a good day!

Best,
Bérangère


Saviez-vous que la Communauté est disponible en Français ?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres !

Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings!


0 Upvotes
MFriberg
Participant

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

SOLVE

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?

0 Upvotes
MiaSrebrnjak
Community Manager
Community Manager

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

SOLVE

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   


Wusstest du, dass es auch eine DACH-Community gibt?
Nimm an regionalen Unterhaltungen teil, indem du deine Spracheinstellungen änderst


Did you know that the Community is available in other languages?
Join regional conversations by
changing your language settings