Variables - Automatic update code

agardenat
Level 1
Variables - Automatic update code

Hello !

I read on the documentation that global variables can be dynamically modified at project run by auto execution the get_variables() code defined in Administration / Variables Automatic update code.

It seems nice but as I see it is Jython only, is there any way to use some contextual data like custom variables / user property / username / etc from there ?

 

Thanks in Advance !

Antoine

 

0 Kudos
3 Replies
ZachM
Dataiker

Hi @agardenat,

You won't be able to access that information using the automatic update code since it uses Jython.

As an alternative, you could use Python code in a scenario to set the global variables. This uses regular Python, so you have full access to Python modules.

 

Preview of the scenario:

image.png

 

Example code that sets the "my_var" global variable:

from dataiku.scenario import Scenario

scenario = Scenario()

scenario.set_global_variables(
    my_var="foo"
)

 

Reference documentation: Scenarios (in a scenario) 

 

Thanks,

Zach

0 Kudos
agardenat
Level 1
Author

Hi @ZachM 

 

Thanks for your answer.

I sure can do that, but I will miss the "automatic" part which made it transparent, with no need to add code to scenarios.

 

Thanks,

Antoine

0 Kudos
ZachM
Dataiker

Hi @agardenat,

You can update the variables automatically by adding a trigger to the scenario. For example, a time-based trigger will cause the variables to be updated on a schedule, such as once every day.

Reference: Scenario Triggers.

0 Kudos