Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Ostrzak
Helper II
Helper II

Referencing notebook exit value as a variable in a data pipeline

Hi everyone,

 

In general: I am trying to build a pipeline around multiple PySpark notebooks, with some additional pipeline features. To achieve it I need to pass values from a notebook to a pipeline.

I checked several pages concerning the topic and consensus was to use Exit Value in the notebook:

 

mssparkutils.notebook.exit(variable)

 

And then create a pipeline variable, and then in Set variable pipeline activity use a dynamic expression:

 

@activity('Notebook_name').output.status.Output.result.exitValue

 

 

For some reason I get such error in Set Variable activity:

 

The expression 'activity('Notebook1').output.status.Output.result.exitValue' cannot be evaluated because property 'Output' cannot be selected. Property selection is not supported on values of type 'String'.

 

I can't find anything on it's origin and what I should change. I tried formatting exit value as an number or string and it doesn't help.

 

I would appreciate the help. If there is another way to "pass" values from the notebook to the pipeline, please let me know; I need it to work further.

1 ACCEPTED SOLUTION

For my own implementation the delimited string just wasnt flexible enough - so here's a version using a JSON object as the notebook return value: 

 

Notebook pyspark:

 

lResult={"numUpdated":10,"message":"success","fruit":["apple","orange","grapes"]}
mssparkutils.notebook.exit(str(lResult))

 

Expression for varMessageStr:

 

@Json(activity('Test Notebook').output.result.exitValue).message

 

Expression for varNumUpdatedInt:

 

@INT(json(activity('Test Notebook').output.result.exitValue).numUpdated)

 

Expression for varFruitArray:

 

@Json(activity('Test Notebook').output.result.exitValue).fruit

 

NotebookReturnsObject.jpg

View solution in original post

14 REPLIES 14
Nero
Advocate II
Advocate II

I also struggled, until I tried ignoring the expression builder syntax errors and just ran my pipeline. I was able to get the following to work by using a delimited string as the notebook return value.

Notebook pyspark:

 

lResult="returnValueOne=25|returnValueTwo=abc|returnValueThree=19"
mssparkutils.notebook.exit(str(lResult))

 

Expression for varAllReturnValuesArray

 

@split(activity('Test Notebook').output.result.exitValue,'|')

 

Expression for varReturnValueOneString

 

@last(split(first(split(activity('Test Notebook').output.result.exitValue,'|')),'='))

 

Expression for varReturnValueTwoString

 

@last(split(split(activity('Test Notebook').output.result.exitValue,'|')[1],'='))

 

NotebookReturnsString.jpg

 

For my own implementation the delimited string just wasnt flexible enough - so here's a version using a JSON object as the notebook return value: 

 

Notebook pyspark:

 

lResult={"numUpdated":10,"message":"success","fruit":["apple","orange","grapes"]}
mssparkutils.notebook.exit(str(lResult))

 

Expression for varMessageStr:

 

@Json(activity('Test Notebook').output.result.exitValue).message

 

Expression for varNumUpdatedInt:

 

@INT(json(activity('Test Notebook').output.result.exitValue).numUpdated)

 

Expression for varFruitArray:

 

@Json(activity('Test Notebook').output.result.exitValue).fruit

 

NotebookReturnsObject.jpg

This is exactly what I needed. Thank you!

sam_wise
Frequent Visitor

Bravo! This was extremely helpful!

 

Many thanks!

Just want to say that this post was EXTREMELY helpful to me and I want to say thank you for sharing this really nice approach.  

Ostrzak
Helper II
Helper II

An update: I found out that changing Set variable activity to:

@activity('Notebook_name').output.result.exitValue

... solves the main problem.

 

I still haven't figured out how to pass multiple notebook values to pipeline variables, so if anyone could help me I will be grateful.

Hi @Ostrzak 

 

We can pass multiple parameters from Notebook to a pipeline using list of parameters. I have attached the screenshots along with the steps for your reference.

1) Create a list of parameters inside a notebook.

vcboorlamsft_0-1698845106159.png

2) Using notebook and set variable activites we can pass the parameters to a pipeline.

vcboorlamsft_1-1698845224966.png

 

I hope this information is helpful. Please do let us know if you have any questions.

 

Thank you for this infomation @v-cboorla-msft .
Can you also help specifying what is the type specified for the variable and what is the expression used in the set variable please?

Thanks,

Prabhat

Hi @v-cboorla-msft 

 

Thank you for your answer. I got to that point independently but I can't parse the exit value so that I get several independent variables out of it. It would be great to know how to tackle that problem.

 

Additionally, is there a more advanced documentation for expression builder? I found this page and it's pretty fine, but it doesn't go beyond the functions listed in the builder. Even the expression I used in Set Variable (see my second post) was found through trial and error, after an extensive web search; it was not efficient.

 

Thank you in advance for any help.

@Ostrzak - This request is really similiar to one I replied to a few months back. (https://community.fabric.microsoft.com/t5/Data-Pipeline/Use-Notebook-Variable-in-Email-Activity/m-p/...

 

If you send back a JSON object you can convert the string in the pipeline use @Json() and then reference values within the JSON object.

 

  • @Json(activity(<activity_name>).output.result.exitValue).<property>

Hi @Ostrzak 

 

Apologies for the delay in reply from our side. Did you got a resolution for this?
In case if you have any resolution please do share that same with the community as it can be helpful to others .
Otherwise, will respond back with the more details and we will try to help .

Hi @Ostrzak 


We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. In case if you have any resolution please do share that same with the community as it can be helpful to others.

Hi @v-cboorla-msft 

 

I haven't found a solution to this problem yet. 

Hi @Ostrzak 

 

Thanks for using Fabric Community.

We are reaching out to the internal team to get more information related to your query and will get back to you as soon as we have an update.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.