[WEBAPP] How to run a scenario with a local variable

Solved!
Redouxne
Level 2
[WEBAPP] How to run a scenario with a local variable

I have a python recipe in my scenario working with a local variable. 

I have succesfully executed my scenario within the webapp but :

How can I change the local variable from the webapp's code (in the Python back-end) ? 

0 Kudos
1 Solution
SarinaS
Dataiker

Hi @Redouxne,

Are you using a scenario variable or a project variable? Indeed, for scenario variables, it's only possible to set them from within the context of a scenario.

So, if you want to set a variable that will be used in a scenario but set it from a Webapp, you'll probably want to use a project variable instead. You can see the following code example for how to set a variable from the Python API, which can be run in the Python backend. 

import dataiku 
client = dataiku.api_client()
project = client.get_default_project()

variables = project.get_variables()
variables['standard']['some_variable'] = 'some_value'    
project.set_variables(variables)

 
Then, from your scenario you can obtain this variable in a Python step:

import dataiku 
client = dataiku.api_client()
project = client.get_default_project()

variables = project.get_variables()
some_variable_value = variables['standard']['some_variable']


Let me know if this approach doesn't work for you! 

Thank you,
Sarina

View solution in original post

0 Kudos
3 Replies
SarinaS
Dataiker

Hi @Redouxne,

Are you using a scenario variable or a project variable? Indeed, for scenario variables, it's only possible to set them from within the context of a scenario.

So, if you want to set a variable that will be used in a scenario but set it from a Webapp, you'll probably want to use a project variable instead. You can see the following code example for how to set a variable from the Python API, which can be run in the Python backend. 

import dataiku 
client = dataiku.api_client()
project = client.get_default_project()

variables = project.get_variables()
variables['standard']['some_variable'] = 'some_value'    
project.set_variables(variables)

 
Then, from your scenario you can obtain this variable in a Python step:

import dataiku 
client = dataiku.api_client()
project = client.get_default_project()

variables = project.get_variables()
some_variable_value = variables['standard']['some_variable']


Let me know if this approach doesn't work for you! 

Thank you,
Sarina

0 Kudos
Redouxne
Level 2
Author

Hi Sarina,

Thank you ! At first glance it seems to work, I have another question, do you know how to know when the scenario ended and get the information in my Python back-end ? 

Thank you again,

Redouane

0 Kudos

Please raise a new thread as this is a different question and this thread has been marked as resolved already.

0 Kudos