using scenarioTriggerName in a scenario step condition
Hi,
how can I reference the trigger name in a step condition of a scenario.
In my situation I want to run step 1 only if the scenario has not been triggered manually, that means triggerName != 'Manual trigger'. But the variable 'triggerName' does not return any value.
Thank you,
Romana
Answers
-
tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner
@Romana
This is a good question and one that I thought would be relatively easy to find an answer for.https://doc.dataiku.com/dss/latest/scenarios/triggers.html#trigger-parameters Says that all triggers pass at least a name and type and some pass additional data (SQL or Python).
Looking here: https://doc.dataiku.com/dss/latest/scenarios/step_flow_control.html#if-condition-satisfied doesn't say anything about accessing the trigger name or type, just the params (if they are defined) as. Upon further inspection of the scenario variables I also did not find it.
One alternative way to do this is without too much difficulty is to make your very first step a Python Step that checks if the scenario was fired manually and then sets a scenario variable (accessible to subsequent scenario steps).
The Python Code:
from dataiku.scenario import Scenario sc = Scenario() # get the handle of the current running scenario trigger_type = sc.get_trigger_type() # get the type of trigger causing sc to run # if triggered manually, set a scenario variable that can be used by other steps if trigger_type == 'manual': sc.set_scenario_variables(scenario_trigger_type='manual') # NOTE: the name of your variable in subsequent steps should match the name of the keyword argument in the set_scenario_variables() method call - Here I chose to Use 'scenario_trigger_type'.
To skip a downstream step if the event was triggered manually.
Let us know if this solution will do what you need it to. I'm fairly certain it does (if I understood the original question).
Thanks,
Tim
-
Hi @tim-wright
,thank you very much for your answer. The solution does exactly what I want, but frankly I wanted to avoid python code. The official documentation claims there is a built in variable (which would make sense). I even found a variable "scenarioTriggerParams" that returns a JSON - unfortunately empty.
Would be great to get an official answer directly from Datiaku admins since it contradicts the documentation.
Romana
-
tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner
@Romana
I completely agree and was also confused by the discrepancy from what I saw and what is in the documentation. It would indeed be great to hear from Dataiku on this.One thing I stumbled across that could help awareness. I created a Python step in a scenario that just prints the available variables -- which I then inspect in the log after running the scenario:
scenarioTriggerParams
scenarioTriggerRunId.get_all_variables() will (reportedly) return all of the variables, including global, project and scenario specific ones. I see the a bunch of scenario specific variables including:
from dataiku.scenario import Scenario sc = Scenario() # get the handle of the current running scenario #### LOOK FOR THIS IN THE LOG AFTER THE STEP RUNS #### print('<<<<<<<< SCENARIO VARIABLES >>>>>>>>>> : {}'.format(sc.get_all_variables())) # All the '<<<<..' just makes spotting this in the Log a little easier
But, I see nothing related to Trigger Name or Trigger Type. I would screenshot what I see in my logs, but it also contains some API keys (stored in my project variables).
Just an FYI
-
dima_naboka Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 28 DataikerHello,Thanks for raising this up. We will be passing this to Product to consider implementing better UX functionality around this logic.For the time being, please follow Tim’s suggestion
-
tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner
@dima_naboka
in addition to the UX logic, I think the part that is potentially misleading is here: https://doc.dataiku.com/dss/latest/scenarios/triggers.html#trigger-parameters where it states "All triggers pass at least their name and type" - not sure if that can be clarified in the documentation until it is implemented.Thanks @dima_naboka
. -
Damo Partner, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts, Dataiku DSS Adv Designer, Registered Posts: 9 Partner
Hello,
Do we have any update for the above discussed feature. we have the same use case and trying to check the manual / auto trigger scenarios. Appreciate your help.
Thank you - Damo