Walter_C
Databricks Employee
Databricks Employee

To access the individual items from your list [1, 2, 3, 4] in the notebook for each iteration of the For Each task, you can use the {{input}} reference. Here’s a step-by-step example to help you understand how to achieve this:

  1. Define the For Each Task:

    • Create a new For Each task in your job configuration.
    • Set the inputs field to your list: "[1, 2, 3, 4]".
    • Configure the nested task that will run for each item in the list.
  2. Configure the Nested Task:

    • In the nested task, use the {{input}} reference to access the current item in the iteration.
    • For example, if you are using a notebook task, you can pass the {{input}} as a parameter to the notebook.
  3. Access the Parameter in the Notebook:

    • In your notebook, use dbutils.widgets.get to retrieve the parameter value.

Here’s an example configuration:

{
  "name": "Process Items",
  "tasks": [
    {
      "task_key": "process_items",
      "for_each_task": {
        "inputs": "[1, 2, 3, 4]",
        "task": {
          "task_key": "process_item_iteration",
          "notebook_task": {
            "notebook_path": "/path/to/your/notebook",
            "base_parameters": {
              "item": "{{input}}"
            }
          }
        }
      }
    }
  ]
}

View solution in original post