Join us on July 16th as we explore real-world Reinforcement Learning Learn more

Multiple SELECT parameters using getChoicesFromPython ?

Level 2
Multiple SELECT parameters using getChoicesFromPython ?

Hi, 

I'm currently writing the parameters in my recipe's JSON. I would like to add 2 SELECT choices, both created via python but with different methods. However, I only see one field (paramsPythonSetup) to insert my python script's name. If I try to implement 2 Do functions in it, both SELECT parameters display the choice list corresponding to the last Do function

So... How can I write 2 python codes to generate 2 choices lists in one parameters' JSON ?

Thx for your help

2 Replies
Dataiker
Dataiker

Hi, 

You will only need 1 function do, and then inside it you do a check on the payload parameter to define which SELECT choice you are dealing with.

Something like this: 

def do(payload, config, plugin_config, inputs):
   if payload.get('parameterName') == 'parameter2':
      choices = [
         { "value" : "val1", "label" : 'value of parameter2 -1'},
         { "value" : "val2", "label" : "Value of parameter 2 - 2"}
]
      return {"choices": choices}

   if payload.get('parameterName') == 'parameter3':
      choices = [
         { "value" : "val1", "label" : "Value of parameter 3 - 1"},
         { "value" : "val2", "label" : "Value of parameter 3 - 2"}
   ]
      return {"choices": choices}

Level 2
Author

Awesome, thank you 🙂