Forum Discussion
Fabric Notebook ExitValue how to select specific values
Hi,
In Fabric Notebook , From the ExitValue below output in Notebook , how to select specific value , like only schema and table and need to select values of schema and table output in Notebook.
ExitValue: {"parent1": {"name": "test", "Details": {"status": "active", "schema": "dbo","table" : "employee}}}
Hi Ka13 ,
Yes we can read this query in a copy activity. First convert this select query to json
import jsonfrom notebookutils import notebooknb_result = {"select_query": select_query}notebook.exit(json.dumps(nb_result))Then in pipeline add notebook activity and connect to copy data. In the dynamic content of copy data, add this json expression.
@json(activity('Notebook1').output.exitValue).select_queryThis works.
If this post helps, please accept this as a solution. Appreciate your kudos.
Thanks,
Pallavi_r
17 Replies
- v-prasareCommunity SupportHi Ka13,You can pass the formed SELECT query to the next Copy Activity by exiting the notebook with the query as JSON and referencing it using dynamic content in the Copy Activity source. This method works reliably in Fabric pipelines and is the recommended way to execute dynamic SQL from a notebookThanks,prashanthMS fabric community support
- Ka13Helper II
Thanks Prasare, will test and let you know if any issues.
- pallavi_rSuper User
Hi Ka13 ,
The exitvalue returned from mssparkutils.notebook.run() is always a string. We need to first parse into json using function - json.loads to access its element. Please see the below code.
import jsonparsed = json.loads(exit_value)schema = parsed["parent1"]["Details"]["schema"]table = parsed["parent1"]["Details"]["table"]The above code worked for me. Please see and let me know if it resolves this issue.
If this post helps, please accept this as a solution. Appreciate your kudos.
Thanks,
Pallavi_r
- Ka13Helper II
Thanks Pallavi for your reply.
Can we pass the above ExitValue from one notebook to another Notebook activity and access the values of schema and table in another Notebook?. Can you please suggest
- v-prasareCommunity Support
Hi @RajK2,
thanks for explaining the scenario. To better understand the issue and provide an accurate solution, could you please share a small set of sample data (with any sensitive information removed) along with the expected output? This will help ensure the guidance is aligned with your exact requirement.
Thanks,
Prashanth
MS fabric community support
- Ka13Helper II
Hi Prasare , I tried the below solution provided by Pallavi it worked
In Notebookimport json
from notebookutils import notebook
nb_result = {
"select_query" = select_query
}
notebook.exit(json.dumps(nb_result))
Then in pipeline, added notebook activity. In the dynamic content added the json
Anonymous(activity('Notebook1).output.exitValue).select_query