---
parser: v2
author_name: Aviral Agarwal
author_profile: https://github.com/aviral-agarwal-sap
auto_validation: true
time: 60
tags: [ tutorial>intermediate , software-product>sap-business-technology-platform, tutorial>free-tier]
primary_tag: software-product>sap-build-process-automation
slug: spa-order-management-int-2-automation
canonical_url: https://developers.sap.com/tutorials/spa-order-management-int-2-automation
---

# Automate the Extraction of Order Details in Orders Management Application
<!-- description --> Automate the extraction of order details and product's details in Orders Management application.

## Prerequisites
- You have completed the first exercise: [Capture Orders Management SAP UI5 Application Using Recorder](spa-order-management-int-1-recorder)

## You will learn
  - How to build an automation in SAP Build Process Automation to extract data from a SAPUI5 screen.
  - How to get the header and line items data of a table.
  - How to use sub-automations.

## Intro
The screens and elements have been defined. You can now create the actual automation.

Think about what your bot should do. On a very high level it must:

- Open Excel and read supplier name from there.
- Open a Orders Management application in a web browser and extract order details from there, based on the supplier name from Excel.
- Write the order details back into Excel.

---

### Define the automations


> **NOTE**: You can reuse the automation **Orders Management Automation** created by the screen recorder and modify it later.

For now, start by creating two additional automations: the main one (named **Order Management**) and an other one for Excel (named **Write Excel**).

1.  Make sure that the **Overview** tab is selected and then click the **Create** button and select the **Automation** artifact from the artifact menu.

    ![001](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/001.png)

2.  Name the Automation: **Order Management** and click **Create**.

    ![002](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/002.png)

    An empty automation is created.

3.  Go back to the **Overview** tab, create a new Automation and name it: **Write Excel**.

    Now you have three Automations:

    ![003](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/003.png)

    Let's reuse the  Recorder generated automation **Orders Management Automation**. Rename it to **Web Portal**. You can also use it as a sub-automation to open the web  (Orders Management Application) and extract the needed data.

4.  Activate the **Orders Management Automation** tab. If the tab is closed, go to **Overview** and open it.

5.  Go to the **Info** section of **Automation Details**.

6.  Change the **Name** of the automation to **Web Portal**.

7.  Click **Save**.

    ![004](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/004.png)

### Main automation - Order Management

In this automation, you will retrieve the data from this [excel](https://github.com/sap-tutorials/sap-build-process-automation-Contribution/blob/main/tutorials/spa-order-management-int-2-automation/Demo_procurement.xlsx).

Define the general structure of the automation. The following is the data that needs to be retrieved from excel:

![010](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/010.png)



1.  Add the **Open Excel Instance** activity to the automation to open an Excel.

    ![011](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/011.png)

2.  You want to open the correct workbook. Add the **Open Workbook** activity.

    ![012](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/012.png)

    In the **Input Parameters** on the right, fill the `workbookPath` field with the path to the file and select the proposed string.

    ![013](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/013.png)

    Or you can edit the expression and enter the full path to your file. Make sure the path is within quotation marks **"..."**. For example: `"C:\Users\Public\sbpa\Demo_Procurement.xlsx"`

    ![014](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/014.png)

3.  Now, you must open a specific worksheet. Add the **Activate Worksheet** activity.

    ![015](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/015.png)

4.  Set `worksheetName` field to **Overview**.

    ![016](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/016.png)

5.  Finally, you must get a value from a cell.

    - Add the **Get Values (Cells)** activity
    - Set `rangeDefinition` field to `B1`
    - Rename **Output Parameters** to `supplierName`

    ![017](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/017.png)

    So far, you read Excel Cell B1 and saved the result in a variable called `supplierName`.

    ![018](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/018.png)

6.  Add **Web Portal** and **Write Excel** sub-automations. They just act as placeholders.

    ![019](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/019.png)

7.  At the end you must make sure that Excel is not used by SAP Build Process Automation anymore. Therefore, you add the **Release Excel Instance** activity to release the instance.

    ![020](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/020.png)

8. Click **Save**.

    Now, you check how the bot works and if the automation has any mistakes.

9.  Click the **Test** button.

    ![021](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/021.png)

10. Click **Test**.

    ![023](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/023.png)

Once the automation is completed, you can see the debug screen (Tester). Here, you can either check the output of the **Test Console** or click on single steps in the automation to see the details on the right side.

For instance, click on the **Get Values (Cells)** step and you can see the correct output value on the right **Bottom-Dollar Markets**. The automation ran correctly.

![027](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/027.png)

> **NOTE**: Please don't forget to close both excel, as well as the SAPUI5 application each time you test the automation.



### Web Portal automation - Search for order number


The Recorder created an automation that you renamed to **Web Portal**. On a high level, refer to the following steps:

  - Enter supplier name in the search box and search.
  - Click on the result.
  - This will open the details of the order.

Now, you must modify the recorded automation and enhance it. You must make sure that your bot saves all the relevant information which you will later write into Excel.

1.  Open the **Web Portal** automation, either on the left menu or on the tab on the top.

    ![028](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/028.png)

2.  Click on the **Start Web Page** step. There is no need to modify anything however if you want, here you can change the default web browser application. Select only chromium web browsers (Chrome or Microsoft Edge).

    ![029](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/029.png)

3.  Click on the **Browse Orders** and choose **Define Screen Activities**.

    ![030](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/030.png)

4. To make your automation more robust, you must be sure that the screen is fully loaded.
   Search for the **Wait (Screen)** activity, and drag and drop it after the **Start Web Page** activity. SAP Build Process Automation will wait until the screen is fully loaded.

    ![031](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/031.png)

    ![032](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/032.png)

5.  Additionally, SAP Build Process Automation must wait to ensure that the search box loads as well. Search for the **Wait (Element)** activity.
   You have two options on how to add it to your automation. Check them and apply the one you prefer.

**OPTION 1**: Drag and drop the **Wait (Element)** activity on the search box. Make sure the cursor changes to **+** before releasing. The step is added as the last one. Move it just after the **Wait (Screen)** step.

![033](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/033.png)

![034](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/034.png)

![035](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/035.png)

**OPTION 2**: Drag and drop the **Wait (Element)** activity after the **Wait (Screen)** step.

![036](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/036.png)

Click on the **Target** editor.

![037](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/037.png)

Select the Search Field element and click **Confirm**.

![038](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/038.png)

### Input parameter

In the **Set Element (SAPUI5 Recorder)** step, you search for the supplier name. You recorded a fixed value and now, you must modify the automation in such a way that you search for a value defined in Excel.

But how to get the name of the supplier from Excel? It's not available in the **Web Portal** sub-automation yet. That variable is only available in the main **Order Management** automation. But you can pass the variable to the sub-automation using **Parameters**.

1.  First, rename the automation label from **Set Element (SAPUI5 Recorder)** to **Search String**.

    ![039](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/039.png)

2.  Click on an empty space to change the settings of the automation. Click the **Input/Output** tab and then click **Add new input parameter**.

    ![040](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/040.png)

3.  Create an input parameter named `CustomerName`.

    Make sure that the type is **String**. Click on an empty space (or press **Enter**).

    ![041](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/041.png)

4.   Go back to the **Search String** step, delete the old value and select the `CustomerName` variable, which is the input parameter passed to the sub-automation.

   ![042](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/042.png)

   Click **Save**.

   However, the value still hasn't been passed from the main automation. To do that:

5.   Go to the main automation either from the left side or from the tabs at the top. Select the **Web Portal** step and set the `CustomerName` field to `supplierName`.

   ![043](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/043.png)

6.   Click **Save**.


### Web Portal automation - Get Order info


Next, make sure that your search results are loaded before you continue with your automation.

1.  Add the **Wait (Element)** activity just after the **Search String** step.

    ![046](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/046.png)

2.  Click **Target**, select the `OrderFound` element and choose **Confirm**.

    ![047](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/047.png)

3.  SAP Build Process Automation should wait for the details screen to open and load. Add a **Wait (Element)** step.

    ![048](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/048.png)

4.  Click **Target**, select the **Price** element and choose **Confirm**.

    ![049](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/049.png)

5.  Save the Order Number in a variable. Click on the **Get Element** step.

    ![050](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/050.png)

6.  Set the target to **Order Number** element and choose **Confirm**.

    ![051](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/051.png)

7.  Rename the output parameter field to `orderNumber`.

    ![052](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/052.png)

8.  You can test now. If you go to the main automation (tab **Order Management**) and start test, you must select an environment. Don't forget to close excel.

    If you remain in the Web Portal tab, you must enter `CustomerName` because you will only test this automation and value will not be fetched from Excel (enter search value: **Bottom-**).

    In both cases, you will see that the received get element value is **Order 2686**.

    ![053](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/053.png)

9.  Next, get the **Price** element and save it in the **price** variable.

    ![054](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/054.png)

10. If you run a test again you can check the value.

    ![055-test](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/055.png)

    > **NOTE**: You can also rename these two **Get Element** activities to more meaningful names (for example, **Get Element (price)** and  **Get Element (order number)**).


### Web Portal automation - Get Shipping Address and Line Items information using multi-level collection


1. Use the **Get Element** activity for the **Shipping Address** table. Drag and drop the activity on the table.

2. Select **ITEM: Shipping Address** and **INDEX: all**.

    ![056](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/056.png)

    The shipping address is nested so a "For Each" loop has been automatically created.

    ![057](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/057.png)

3. Click on the **Get Element** activity and define the **Output Parameters** field to **array**.

4. Click **Save**.

    ![058](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/058.png)

5. Use the **Get Element** activity for the **Line Items** table. Drag and drop the activity on the Table Data.

6. Select **ITEM: Table Data** and **INDEX: all**.

    ![059](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/059.png)

    The Table Data is **Two-Dimensional**, hence **two** "For Each" loop have been automatically created.

    ![060](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/060.png)

7. Click on the **Get Element** activity and define the **Output Parameters** field to `TableCellData`.

8. Click **Save**.

    ![061](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/061.png)

    Use the **Log Message** activity to display the values of each element.

9. Search for the **Log Message** activity and drag and drop into the workflow after the **Get Element** step of the **For Each - 3** loop

    ![062](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/062.png)

10. Click on the **Log Message** activity and select `TableCellData` in the **message** field.

11. Click **Save**.

    ![063](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/063.png)

12. Add another **Log Message** activity to display the value of the row number. Drag and drop it after the **For Each - 2** loop.

    ![064](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/064.png)

13. Click on the **Log Message** activity, and click the expression editor button for the **Input Parameters** message.

14. Edit the expression to **'Row no :' + Step13.index**.

    > **NOTE**: Step number 13 is the first for loop to display the row count.

    ![065](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/065.png)

15. Click **Save** and test the automation. As you can see in the **Test Console**, all the product information, product name, unit price, quantity, and total amount are displayed cell by cell.

    ![066](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/066bis.png)



### Create Data Types for Shipping Address and Line Item


The name, address, zip and so on from the shipping address are currently stored in an array. You can add better structure to that by using **Data Types** from SAP Build Process Automation. These data types can store multiple variables and named fields to represent more complex data structures. Create two data types: one for a shipping address and another for a line item.

**Save** the automation you have so far. Go to **Overview** tab.

1.  Click **Create** > **Data Type**.

    ![057](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/057bis.png)

2.  Name the data type **Line Item** and click **Create**.

    ![058](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/058bis.png)

3.  Repeat the same steps to create another data type named **Shipping Address**.

    ![059](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/059bis.png)

4.  Now, go back to the **Line Item** data type, create a new field by clicking on **New Field**.

    ![060](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/060bis.png)

5.  Adjust the field properties to name **Product** and type **String**.

    ![061](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/061bis.png)

6.  Repeat the steps to create the other fields: `UnitPrice`, `Quantity`, `Total`. All of these are type **String**.

    ![062](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/062bis.png)

7.  Repeat same steps to create fields inside the **Shipping Address** datatype: **Name**, **Street**, **ZIP**, **Region**, **Country**. All of these are type **String**.

    ![063](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/063bis.png)

8.  Click **Save** to save both data types.


### Add Shipping Address Data Type in Web Portal automation


1.  Go back to the **Web Portal** automation and drag and drop the **Shipping Address** data type just after the **Get Element (Price)** step.

    ![067](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/067bis.png)

2.  Define the **Output Parameters** field to `shippingAddress`.

    ![068](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/068bis.png)

3.  Select the **Input Parameters** value to **Create Custom Data**.

    ![069](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/069bis.png)

    ![070](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/070bis.png)

4.  Drag a **Condition** step and drop it under **Get Element** step.

    ![071](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/071bis.png)

5.  Select the **Condition** step and click **Edit Formula**.

    ![072](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/072bis.png)

6.  In the Expression Editor, type **Step11.index === 0** and click **Save Expression**.

    ![073](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/073bis.png)

7.  Choose **Add Condition** and type the following formula in the **Expression Editor**:
    - **Step11.index === 1**

    ![073](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/122.png)


8.  Similarly, add three other Conditions and enter the following formulas in the **Expression Editor**:
    - **Step11.index === 2**
    - **Step11.index === 3**
    - **Step11.index === 4**

    The automation will look like this:

    ![074](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/074bis.png)

9.  Now, drag a **Set Variable Value** activity and drop it below the first condition.

    ![075](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/075bis.png)

10. Click on the **Set Variable Value** activity and change the step name to **Set Variable Name**.

11. Select the **variable** field value to `shippingAddress`.

12. Select the **value** field value to **Custom Data**.

13. Select the **Name** field value to **array**.

    ![076](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/076bis.png)

14. Drag a **Set Variable Value** activity and drop it under each Condition.

15. Repeat steps 10-13 with the below information :


|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Street**
|  variable          | `shippingAddress`
|  value    | **Street: array**


|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Zip**
|  variable          | `shippingAddress`
|  value    | **Zip: array**


|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Region**
|  variable          | `shippingAddress`
|  value    | **Region: array**


|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Country**
|  variable          | `shippingAddress`
|  value    | **Country: array**

  ![077](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/077bis.png)


### Add Line Item Data Type in Web Portal automation


Start by creating a variable which will contain multiple line items.

1.  Add the **Line Item** data type after the **For Each** loop.

2.  Make sure to check the **list** option and define the **Output Parameters** field to `lineItems`.

    ![078](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/078bis.png)

3. Now add a **Line Item** data type inside the **For Each - 2** loop.

4. Select the **Input Parameters** value to **Create Custom Data**.

5. Set the **Output Parameters** field to `lineItem`.

    ![079](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/079bis.png)

6. Drag an **Add Item (List)** activity and drop it as well in the **For Each - 2** loop, after **Log Message** activity.

    ![080](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/080bis.png)

7. Select the **Add Item (List)** activity and set the `list` field value to `lineItems` and `itemToAdd` field value to `lineItem`.

    ![081](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/081bis.png)

8. Drag and drop a **Condition** step in the **For Each - 3** loop after **Get Element** activity.

    ![082](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/082bis.png)

9. Add four Conditions with the following **Condition Expression**:

    - **Step24.index === 0**
    - **Step24.index === 1**
    - **Step24.index === 2**
    - **Step24.index === 3**

    ![083](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/083bis.png)

10. Now, drag and drop a **Set Variable Value** activity for each Condition.

    ![084](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/084bis.png)

11. Click on the **Set Variable Value** activity and change the step name to **Set Variable Product**.

12. Select the **variable** field value to `lineItem`.

13. Select the **value** field value to **Custom Data** value.

14. Select the **Product** field value to `TableCellData`.

    ![085](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/085bis.png)

Repeat steps 11-14 with the following information :

|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Unit Price**
|  variable          | `lineItem`
|  value    | Unit Price: `TableCellData`


|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Quantity**
|  variable          | `lineItem`
|  value    | Quantity: `TableCellData`


|  Field Name     | Value
|  :------------- | :-------------
|  Step Name           | **Set Variable Total**
|  variable          | `lineItem`
|  value    | Total: `TableCellData`

![086](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/086bis.png)



### Input/Output parameters


Now, you have to pass data between sub-automations. You can do this by using input and output parameters.

The web automation will get the partner name from the main automation and return the order number, price, shipping info and line item details. This data will in turn be passed to the excel automation.

1.  Select the **Web Portal** automation. Click anywhere on the grey area to open the automation parameters.

2.  Make sure that an input parameter called `CustomerName` of type **string** is defined.

    ![091](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/091bis.png)

3. Create output parameters and make sure that the **List** box is checked for Line Item parameter.

    | Name        | Type           | List  |
    | ------------- |-------------| -----|
    | `orderNumber`     | String | no |
    | `price`     | String      |   no |
    | `shippingAddress` | Shipping Address      |    no |
    | `lineItems` | Line Item      |    yes |

    ![092](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/092bis.png)

4.  Now, you define which variables will be returned. Click on **End** step, select **Parameters** and select the respective variables for outputs.

    ![093](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/093bis.png)

5.  Click **Save** to save the automation.


### Write Excel automation - First Worksheet


Now, you must automate the Excel part. You have collected the data from the SAPUI5 application. You must insert the data back into Excel. You will do this in the **Write Excel** sub-automation.

The following is the expected result:

   ![096](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/096.png)

   ![097](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/097.png)

1. Switch to the **Write Excel** automation. Start by adding input parameters, which you received from the **Web Portal** sub-automation.

    ![098](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/098.png)

2.  Add the same input parameters as the output parameters you added in the web automation.

    | Name        | Type           | List  |
    | ------------- |-------------| -----|
    | `orderNumber`      | String | no |
    | `price`     | String      |   no |
    | `shippingAddress` | Shipping Address      |    no |
    | `lineItems` | Line Item      |    yes |

    ![099](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/099.png)

    You can further enhance the bot by setting all the product details in the Excel. Use the **Set Values** activity of Excel to set the values in the Excel.

3.  Use the **Set Values (Cells)** activity to write data into a specific cell. Drag and drop the activity into the workflow of the automation.

    ![102](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/102.png)

4.  Click on the **Set Values (Cells)** activity, change the name to **Set Cell (Order Number)** and set the `rangeDefintion` field value to `B2` and `values` field value to `orderNumber`.

    ![103](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/103.png)

5.  Duplicate this step (right click on **Set Values (Cells)**).

    ![104](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/104.png)

6.  Change the name to **Set Cell (Price)** and set `rangeDefinition` field value to `B3` and `values` field value to `price`.

    ![105](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/105.png)

7.  Duplicate this step (right click on **Set Cell (Price)**).

8.  Change name to **Set Cell (Name)** and set `rangeDefinition` field value to `B4`.

9.  Change the **values** using the expression editor, to get the value inside the data type.

    ![106](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/106.png)

10. Write **Step0.shippingAddress.Name** in the **Expression Editor**.

    >**NOTE**: **Step0** contains the input parameters.

    ![107](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/107.png)

7.  Duplicate the steps to save time and adjust the parameters according to the following table:

    | `rangeDefinition`        | **values**          |
    | ------------- |-------------|
    | `B2` | `orderNumber` |
    | `B3` | price     |
    | `B4` | Step0.shippingAddress.Name      |
    | `B5` | Step0.shippingAddress.Street      |
    | `B6` | Step0.shippingAddress.ZIP      |
    | `B7` | Step0.shippingAddress.Region      |
    | `B8` | Step0.shippingAddress.Country      |

    ![108](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/108.png)



### Write Excel automation - Second Worksheet


Now, you will add a second worksheet for the line item details.

Desired result:

![109](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/109.png)

1.  Drag and drop an **Activate Worksheet** activity and configure `worksheetName` field value to **Details**.

2. Click **Save**.

    This action will switch to the second worksheet with the order details.

    ![110](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/110.png)

3.  Add a **For Each** control to loop through the order line items. The **looping list** is `lineItems`.

    ![111](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/111.png)

4.  Drag and drop a **Set Values (Cells)** activity inside the loop.

    ![112](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/112.png)

5.  The data cells start at row **2**, the index starts at **0**, so use the following formula in the `rangeDefinition` field to determine the correct cell:

    **"A" + (Step9.index + 2)**

    For the Values parameter, set the `values` field value to:

    **Step9.currentMember.Product**

    > **NOTE**: Make sure that you use the **Edit Expression** to enter formulas in `rangeDefinition`. The text should be in blue color, not black!

    ![113](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/113.png)

6.  Duplicate and repeat for **Unit Price**, with column `B` instead.

    ![114](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/114.png)

7.  Duplicate and repeat for **Quantity**, with column `C` instead.

    ![115](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/115.png)

8.  Duplicate and repeat for **Total**, with column `D` instead.

    ![116](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/116.png)

9.  Save all automations.


### Adding the headers


1. To add the headers : drag four **Set Values (Cells)** activities and drop them into the workflow after **Activate Worksheet**.

2. Adjust the parameters according to the following table:

    | `rangeDefinition`       | **values**          |
    | ------------- |-------------|
    | `A1` | Product |
    | `B1` | Price     |
    | `C1` | Quantity     |
    | `D1` | Total      |

    ![117](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/117bis.png)


### End


1. Within the main automation **Order Management**, you pass the outputs from **Web Portal** into the inputs of **Write Excel**

    ![117](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/117.png)

2. Make sure that output parameters are defined for both sub-automation as displayed in the following screenshots:

    ![118](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/118.png)

    ![119](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/119.png)

3.  Now, you can test the automation. You must see the following results:

   ![120](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/120.png)

   ![121](https://raw.githubusercontent.com/sap-tutorials/sap-build-process-automation/main/tutorials/spa-order-management-int-2-automation/images/121.png)

Congratulations! You have now completed this tutorial that read complex data from a website and stored it into an Excel file with two Worksheets.

