APIs & Integrations

RWeir2
Member

Custom Code Not Working in Workflow

Hi folks,

 

I'm having some trouble with the custom code I wrote for a workflow. We have a page where our potential customers can sign up for a variety of free trials. On that page, there is a free trial ID that gets passed back to us through the form so we know exactly which free trial they signed up for, and that ID indicates all of the information we need to create a deal (subject, location, date, and time). I'm trying to use the custom code pictured below to make deal creation easier:

 

def main(free_trial_id):
  free_trial_name = free_trial_id[0] + free_trial_id[1]
  free_trial_location = free_trial_id[4]
  free_trial_date = free_trial_id[5] + free_trial_id[6] + free_trial_id[7] + free_trial_id[8]
  free_trial_time = free_trial_id[9] + free_trial_id[10] + free_trial_id[11] + free_trial_id[12]
  if free_trial_name == "01":
    free_trial_name = "Scratch JR. Free Trial"
  elif free_trial_name == "02":
    free_trial_name = "Robotics - ages 5-8 Free Trial"
  elif free_trial_name == "03":
    free_trial_name = "Scratch Free Trial"
  elif free_trial_name == "04":
    free_trial_name = "Minecraft Free Trial"
  elif free_trial_name == "05":
    free_trial_name = "Roblox Free Trial"
  elif free_trial_name == "06":
    free_trial_name = "Python Free Trial"
  elif free_trial_name == "07":
    free_trial_name = "Robotics - ages 9-13 Free Trial"
  elif free_trial_name == "08":
    free_trial_name = "Java Free Trial"
  elif free_trial_name == "09":
    free_trial_name = "Javascript Free Trial"
  elif free_trial_name == "10":
    free_trial_name = "FLL Free Trial"
  elif free_trial_name == "11":
    free_trial_name = "ACSL Free Trial"
  elif free_trial_name == "12":
    free_trial_name = "Mobile Apps Free Trial"
  elif free_trial_name == "13":
    free_trial_name = "AP Java Free Trial"
  else:
    free_trial_name = "Free Trial"
  
  if free_trial_location == "1":
    free_trial_location = "Park Slope"
  elif free_trial_location == "2":
    free_trial_location = "Cobble Hill"
  elif free_trial_location == "3":
    free_trial_location = "Lexington"
  elif free_trial_location == "4":
    free_trial_location = "Acton"
  elif free_trial_location == "5":
    free_trial_location = "Newton"
  elif free_trial_location == "6":
    free_trial_location = "Online"
  else:
    free_trial_location = "Default"
    
  if free_trial_location == "Online":
    if int(free_trial_id[9]) == 1:
      free_trial_time = free_trial_id[9] + free_trial_id[10] + ":" + free_trial_id[11] + free_trial_id[12] + "AM EST"
    else:
      free_trial_time = free_trial_id[9] + free_trial_id[10] + ":" + free_trial_id[11] + free_trial_id[12] + "PM EST"
  else:
    free_trial_time = free_trial_id[9] + free_trial_id[10] + ":" + free_trial_id[11] + free_trial_id[12]
    
  free_trial_date = free_trial_id[5] + free_trial_id[6] + "/" + free_trial_id[7] + free_trial_id[8]
  email = event["inputFields"]["email"]
  # Return the output data that can be used in later actions in your workflow.
  return {
    "outputFields": {
      "free_trial_name": free_trial_name,
      "free_trial_location": free_trial_location,
      "free_trial_time": free_trial_time,
      "free_trial_date": free_trial_date
    }
  }

 

 I keep getting the error "Key error: 0" which to me implies hat the free trial ID isn't making it in to the code even though I specifiy it as a property using the hubspot feature and pass it as a parameter in main. Does anyone have any idea why this may not be working? We have a lot of free trials so this would make deal creation a lot easier for us.

0 Upvotes
1 Reply 1
DianaGomez
Community Manager
Community Manager

Custom Code Not Working in Workflow

Hi @RWeir2

 

Thank you for contacting the Community!

 

I would like to seek the expertise of some HubSpot professionals to gather valuable insights. Hello @louischausse, @Teun, @ChrisoKlepke. Would you kindly share any recommendations for @RWeir2?

 

We highly appreciate the valuable contributions you make!

 

Thanks,

Diana


¿Sabías que la Comunidad está disponible en Español?
¡Participa hoy en conversaciones en el idioma de tu preferencia,cambiando el idioma en tus configuraciones!

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


0 Upvotes