Help Shape the Future of Dataiku Join our User Research Program

Passing global variables to application-as-recipe parameters

sylvyr3
Level 3
Passing global variables to application-as-recipe parameters

I'm trying to develop an application-as-recipe to create a consistent data extract.  My plan is to have this application-as-recipe to function for both building a training dataset and for a daily scoring process.  The process for building the dataset would use fixed start and end dates but the daily scoring process would use a 7 day moving window.  My thought would be to create a scenario where the first step is a custom python script that updates the project's global variables relative to the current date.  Then, I would pass the global variable to the application-as-recipe settings page.

Screen Shot 2021-05-25 at 8.43.21 PM.png

Unfortunately it appears that the appilication-as-recipe will not accept global variables here.  Any thoughts on how I can pass global variables or otherwise update the dates in an automated method?

0 Kudos
2 Replies
fchataigner2
Dataiker
Dataiker

Hi,

the variables of the project are indeed not used for the values of fields of the recipe. But you can have a first "Execute Python code" step in the scenario defining your app-as-recipe task, where you fetch the variables of the project from which the recipe is launched, and adjust the variables in the current project as needed, like

from dataiku.scenario import Scenario
# get the project from which the app-as-recipe is launched
source_project_key = Scenario().get_all_variables()['scenarioTriggerParam_projectKey']
# get its variables, with the public API
import dataiku
source_project = dataiku.api_client().get_project(source_project_key)
source_variables = source_project.get_variables()
all_source_variables = dict(source_variables['standard'])
all_source_variables.update(dict(source_variables['local']))
# then set some variables for the rest of the scenario execution
Scenario().set_scenario_variables(foo=all_source_variables['bar], ...)
sylvyr3
Level 3
Author

What I ended up doing was adding a function to all my python recipes within the application to check if the user passed a valid date string or if they passed the name of the global variable storing the date string.  It's not ideal but gets the job done.

0 Kudos
A banner prompting to get Dataiku DSS