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