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
6 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
Axolotl
Level 2

Hi,

I believe the question was to be able to do such thing (set/update a variable dynamically) without using scenarios.

I have the same needs. For each project, I need to parameterise dynamically, some variables so that I can retrieve the values (user, time) at each execution and this, not in a scenarios (users can execute recipe outside a scenario).
This will allows to trace the use of runs during the design period.

Is there a way to do that ?
Thanks

0 Kudos

Why is not possible to use Scenarios and Scenario variables which are perfect as they are calculated at run time? Running parts of the flow randomly is not a deterministic approach. You can break your flow build in multiple scenarios to allow for piece meal building. I would suggest you start a new thread as it seems you have a slightly different requirement. 

0 Kudos
Axolotl
Level 2

Yes sorry, I was in this thread because I found the same way as agardenat to do such thing : global variables can be dynamically modified at project run by auto execution the get_variables() code defined in Administration / Variables Automatic update code.

I fully agree with you for the scenario usage. But I canot prevent a user starts a new project, then create a handle on data then execute a recipe on it. For this use case, a global variables that can be dynamically modified at project level during execution would be helpfull.

0 Kudos