How to access project/global variables from Scenario Reporter custom script

Tomas
Tomas Registered, Neuron 2022 Posts: 121 ✭✭✭✭✭✭

In scenarios there is a possibility to create custom variables via python code in the "Reporters" section.

How can I access global variable in the python?

Import of dataiku is not possible

<type 'exceptions.ImportError'> : No module named dataiku

import json

import dataiku

# compute your additional variables from the list of report items

# and return them as a dictionary.

def get_variables(items_json, scenario_run_json, step_run_output_json):

items = json.loads(items_json)

client = dataiku.api_client()

client.get_variables()....



Best Answer

  • jereze
    jereze Alpha Tester, Dataiker Alumni Posts: 190 ✭✭✭✭✭✭✭✭
    Answer ✓
    Hi Tomas,

    Indeed, I was not able to import the dataiku module in the Python editor of the "create custom variables" modal.

    However, you should be able to use your custom variables just writing it anywhere you need it : ${my_variable}
    You don't need to change anything in the Python editor.

    I hope this helps.

Answers

  • Tsen-Hung
    Tsen-Hung Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts, Dataiku DSS Adv Designer, Registered Posts: 5 ✭✭✭✭

    @jereze

    Is there also a way to retrieve the variables defined with one of the "steps" under a Scenario?

  • Tanguy
    Tanguy Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron, Dataiku DSS Adv Designer, Registered, Dataiku DSS Developer, Neuron 2023, Circle Member Posts: 144 Neuron

    +1 to the previous question: I failed to do this (and posted a question on this topic)

Setup Info
    Tags
      Help me…