Search code examples
azuremicrosoft-fabricmssparkutils

Microsoft Fabric: mssparkutils.notebook.exit with multiple values or json/dict


In Fabric, I have a notebook with a dataframe and some aggregations. I'm trying to pass those aggregated values further to outlook365 activity. The simplified version of passing aggregations is as follows:

import json

summa = 250
snitt = 100

result = {
    'sum': summa,
    'snitt': snitt
}

result_json = json.dumps(result)

mssparkutils.notebook.exit(result_json)

Inside outlook365 activity I'm trying to caprure a value of "snitt" like this:

@json(activity('exit').output.result.exitValue.snitt)

But getting an error: "The expression 'json(activity('exit').output.result.exitValue.snitt)' cannot be evaluated because property 'snitt' cannot be selected. Property selection is not supported on values of type 'String'."

Any workaround for this? My goal is to get some aggregations from notebook and pass them to outlook365.

I tried to parse the value with @json(activity('exit').output.result.exitValue.snitt) or just with @activity('exit').output.result.exitValue.snitt without success.


Solution

  • The exitValue from the notebook activity exit is of string type. That is the reason you are not able to get the value of 'snitt' from that.

    img:1 Notebook activity output

    The correct way to give the expression is,

    @json(activity('exit').output.result.exitValue).snitt
    

    This expression uses the "json" function to parse the "exitValue" string as a JSON object, and then uses the dot notation to extract the "snitt" value from the object.