APIs & Integrations

dhordos
Member

Custom code output is not defined

hi there,

I have created a custom code, see below. In the data output section I have added test_sao_enter_2 as a date type variable. The code executes successfully, however the data output says the following: "Make sure to define the output "test_sao_enter_2" in the data outputs form using the same name you used in the code.". 

I have no idea what the problem could be. Could you please help me?

Thanks in advance,
Donát

 

 

from datetime import datetime


def main(event):

  enter_dr = event.get('inputFields', {}).get('hs_v2_date_entered_85505052', None)
  enter_pc = event.get('inputFields', {}).get('hs_v2_date_entered_85505053', None)
  enter_n = event.get('inputFields', {}).get('hs_v2_date_entered_85504059', None)
  enter_c = event.get('inputFields', {}).get('hs_v2_date_entered_85504060', None)
  enter_cl = event.get('inputFields', {}).get('hs_v2_date_entered_85505055', None)
  
  def parse_datetime(date_str):
          if date_str:
              try:
                  return datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
              except ValueError:
                  return None  
          return None

      
  dates = [parse_datetime(d) for d in [enter_dr, enter_pc, enter_n, enter_c] if d]
  enter_cl_date = parse_datetime(enter_cl)

    
  valid_dates = [date for date in dates if date and (not enter_cl_date or date > enter_cl_date)]

    
  if valid_dates:
      test_sao_enter_2 = min(valid_dates).isoformat() 
  else:
      test_sao_enter_2 = None  
	
  
    
  
  return {
    "outputFields": {
      "test_sao_enter_2": test_sao_enter_2
    }
  }
  

 

 

 

0 Upvotes
2 Replies 2
SteveHTM
Key Advisor | Partner
Key Advisor | Partner

Custom code output is not defined

@dhordos - the error message is simply informing you that the output properties also need to be defined in the custom code setup dialog. The only pre-defined output property that can be passed to subsequent workflow steps is the execution status.

See the 'add output' link in the screenshot example below:

SteveHTM_0-1715699297186.png

You may say 'why do I have to define these properties twice?' - I'm not defending this custom code dialog - although it has improved greatly ove the time I have been using it.

 

Good luck!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
dhordos
Member

Custom code output is not defined

Hi Steve, 

thank you for your reply. As I mentioned I have defined this variable in the output section and still not accepting it. 

best,

Donát

0 Upvotes