Create an Automation to Extract Data
- How to create an automation in SAP Build Process Automation
- How to use the Excel SDK
- How to use control blocks: Conditions and Loops
Prerequisites
- A windows machine
- If you are using a MAC, please install a VDI
- Install and Setup the Desktop Agent
- Complete Build Your First Business Process with SAP Build Process Automation mission
IMPORTANT: Please refer to sample Sales Order Management (MI03) in the SAP Build Store if you face any issues while following the tutorials. To retrieve the sample refer to step 6 of Run the Process With an Automation.
An Automation is a succession of steps to orchestrate multiple activities and applications on a local machine.
- Step 1
In this exercise, you will automate the process to read the sales order details from an Excel and select the specific sales order details based on the input from the submitted form. To design the automation, you will need an Excel file filled with the sales order data. You can:
-
Download Sales Order Data OR
-
Create the file yourself using the following data:
Order Number Order Amount Order Date Shipping Country Expected Delivery Date Order Status PO7991 410418.22 1/21/2022 United States of America 1/29/2022 In Time PO7918 150935.13 1/22/2022 United Kingdom 1/27/2022 Urgent PO7375 313977.82 1/23/2022 United Kingdom 2/20/2022 In Time PO7311 755055.4 1/24/2022 United Kingdom 3/30/2022 In Time PO6858 429358.4 1/25/2022 United Kingdom 2/20/2022 In Time PO6368 43739.82 1/26/2022 India 3/25/2022 In Time PO6189 483574.12 1/27/2022 Germany 2/5/2022 In Time PO3115 273993.56 1/28/2022 Germany 3/10/2022 In Time PO2686 220887.56 1/29/2022 Germany 3/5/2022 In Time PO8282 436955.64 1/30/2022 United States of America 3/30/2022 In Time -
In the Lobby from the editable version of your project, do the following:
- Select the process Order Processing.
- Choose +.
-
Select Automation.
-
Choose Blank Automation.
-
A pop up will appear to configure the Desktop Agent version. Do the following in the pop up:
- From the dropdown, select the version of the Desktop Agent installed on your machine. It would be displayed with suffix as Registered.
- Under Platforms, choose Windows or Mac depending on the Platforms you are working on.
- Choose the Confirm button.
-
A new pop-up will appear to create the automation. Do the following in the pop-up:
- Under Name enter: Get Order Details.
- Under Description enter: Automation for Order Process.
- Choose the Create button.
Identifier will be auto-filled.
An automation Get Order Details will be created successfully.
-
- Step 2
Business projects usually need to use parameters and variables at runtime. These variables are usually saved in their runtime landscapes for example Dev, Test or Production environments. In this case, you will need to maintain an environment variable that will contain the file full path of the Excel file used in the automation.
Environment Variables allow you to reuse certain information for a given environment. You use environment variables to pass parameters to automations.
-
Select Settings.
-
In the Project Properties window, select Environment Variables, then + Create.
-
In the create an environment variable screen:
- Under Identifier enter:
OrderFilePath
. - Under Type select String.
- Choose the Create button.
- Under Identifier enter:
-
After the Environment Variable is created successfully, close the project properties window.
-
- Step 3
You will now design the automation in the Automation Editor by dragging-and-dropping activities into the workflow of the automation. Later you will configure the inputs and outputs of each activity. You will need activities to interact with the Microsoft Excel application. These activities will open the Excel application, open the workbook that contains the sales orders details, and map them into a data type that will be created during the design. Last, after extracting and mapping the data, the Excel application will be closed.
-
Select three dots next to Get Order Details, choose Open Editor, which navigates to the Design Studio to build the automation.
Since Excel is used in this automation, you have to open an Excel instance. Open Excel Instance is a mandatory activity to use when using Excel. Once you open an Excel instance, you can use other Excel activities.
-
To open the Excel Instance:
- In the Automation Details section on the right, search for the Open Excel Instance activity,
- Drag and drop the activity into the canvas.
Next, Excel Data Mapping is done with the Excel Cloud Link activity. Excel Data Mapping allows you to transform columns-based data from an Excel sheet into data that can be used in the automation. The data from the Excel sheet stays the same but the structure becomes a data type structure, making it possible to use throughout your project.
-
To get the Excel Cloud Link:
- In the Automation Details search for the activity Excel Cloud Link,
- Drag and drop the activity into the canvas.
-
Select Excel Cloud Link, in the details on the right side, choose the Edit activity button.
-
In the Excel File screen:
- Select Browse.
- Choose the Orders.xlsx file which is saved on your machine.
The Excel file is mapped automatically.
-
In the Workbook Path field enter the Environment Variable as
OrderFilePath
, which was created above as the parameter value for Workbook path. -
Select the button + From Excel data.
A pop up appears to create a data type. A Sales Order variable is needed to collect the data from the Excel sheet columns. In this step, a variable is automatically created from the Excel file columns.
-
Under Name of the data type, enter Sales Order and choose the Create button.
Framework creates a data type with the columns of the Excel as the field names. You can see it in the Artifacts section in the Overview tab.
-
Go to Get Order Details automation. In Excel Cloud Link activity on the right side, under Output Parameters, manually change the variable name to Orders.
-
Close the activity.
-
Click on the canvas.
Once Excel is no longer required, close the Excel instance. Close Excel Instance activity closes an instance of Excel.
-
To close the opened instance of the Excel file:
- In the Automation Details search for the activity Close Excel Instance.
- Drag and drop the activity into the canvas and save your automation.
Excel Cloud Link activity is used for:
-
- Step 4
Input and output parameters allow you to exchange data in the workflow of your automation between activities, screens, and scripts.
-
Click on the canvas and select the Input/Output section in Automation Details.
-
Add Input parameters as following:
- In Parameter Name enter:
OrderNumber
. - In Description enter: Receives order number from the Order Processing Form.
- In Data type choose: String.
- In Parameter Name enter:
-
Add Output parameters as following:
- In Parameter Name enter:
SelectedOrder
. - In Description enter: Selected order details are passed to the Process.
- In Data type choose: Sales Order.
- In Parameter Name enter:
-
Save your work.
-
- Step 5
Variables that are used, build your automation, and are data storage that have a name, a type (example: string, list of string or data type), and a value. A variable in the automation is also associated to a step represented by its number.
-
In the Automation Details under Tools:
- Search for the Sales Order data type (created in the previous step).
- Drag and drop the Sales Order data type into the canvas.
A variable of the data type Sales Order is created.
-
Select Create Sales Order variable. Under Output Parameters enter the value as
selectedOrderDetails
. -
Save your work.
-
- Step 6
Now you will loop through each Order from the Excel sheet, retrieve the order details for order number submitted in the Order Processing Form. For Each control allows you to go through a list of members provided as input to your automation, and execute an action for each member in that list.
This control has the following loop parameters:
currentMember
- The member of the list for the current loop iteration.index
- An integer that is the index of the current loop iteration, starts at 0.
-
To loop through each order:
- Click on the canvas.
- In Automation Details search for the control For Each.
- Drag and Drop the activity into the canvas.
-
Select For Each activity, enter the value of Set looping List as Orders.
To match the desired order, a control activity has to be added to search for a match to its order number. The Condition activity is the activity that you will add. In this condition, you will check if the order number entered in the Form is available in data read from Excel in Step 2.
-
To add the condition:
- Click on the canvas.
- In Automation Details search for the activity Condition.
- Drag and Drop the activity inside the For Each block.
-
Choose Condition, select three dots next to Condition Expression field, select Edit Formula.
-
A pop up window appears to enter the condition expression:
- You can enter this expression manually or you can expand the Variables list and select the given variables to form the expression:
Step0.OrderNumber === Step5.currentMember.orderNumber
. - Select the Save Expression button.
If the order number is found in Excel, i.e. the condition is True, set the variable using Set Variable Value activity that is a Data Management activity.
- You can enter this expression manually or you can expand the Variables list and select the given variables to form the expression:
-
To add Set Variable Value:
- Click on the canvas.
- In Automation Details search for the activity Set Variable Value.
- Drag and Drop the activity into the canvas below the condition you set.
-
Select Set Variable Value. In the configuration screen on the right, do the following:
- In the variable field enter
selectedOrderDetails
. - In the value field enter
currentMember
.
Once the order number is found in the Excel, use the control End Loop to stop the loop.
- In the variable field enter
-
To end loop:
- Click on the canvas,
- In Automation Details search for the activity Loop End,
- Drag and Drop the activity into the canvas just below the Set Variable Value.
-
Use Log Message activity to print your results. To add Log Message:
- In Automation Details search for the activity Log message,
- Drag and Drop the activity into the canvas outside the For Each loop.
-
Use the activity to check
selectedOrderDetails
in testing mode. To do that:- Select Log Message,
- In message field, select
selectedOrderDetails
.
-
Save your work.
To loop through data, which activity is used?
- Step 7
Apart from creating an output parameter, it is mandatory to pass the data through the End step to expose the data outside the automation.
-
To do that:
- Select End.
- In the configuration screen on the right, under the Output Parameter, in the
SelectedOrder
field enterselectedOrderDetails
. - Save the Automation.
Make sure to add the steps Condition, Set Variable Value, End Loop inside the For Each block.
-
The complete Get Order Details automation looks as below.
Now you will map the Automation Parameters with the Form Parameters.
-
Select Order Processing process. Choose Get Order Details automation in the process.
-
In Get Order Details, map the input parameter
OrderNumber
of the automation with the Order Number of Order Processing Form. -
Choose the Save button.
-
- Step 8
-
Navigate back to the automation Get Order Details and choose the Test button.
-
In the Test Automation window, enter the parameters to test the Automation:
Parameter Value OrderNumber
Any order number which is available in Sales Order Data Excel OrderFilePath
Path where the Sales Order Data Excel is stored on your local machine Select Test button.
-
Test Results:
- Automation opens the
SalesOrderDetails
Excel. - Reads the Excel content.
- Closes the Excel.
- Loops through Excel and verifies if entered
OrderNumber
is available in the Excel. If theOrderNumber
is available in the Excel, it sets the Orders Details. - Ends the looping.
- Prints the selected order details.
- Automation opens the
-
- Step 9
After the design of the automation that retrieves the data form the Excel file, simplify the start form by deleting the not needed fields.
-
In the Order Processing tab :
- Select three dots next to Order Processing Form.
- Select Open Editor.
-
In the form delete following inputs by selecting the 3 dots next to each input menu and selecting Delete:
- Order Amount.
- Order Date.
- Expected Delivery Date.
- Shipping Country.
-
Save the Form, close the Form Editor and go back to the Order Processing tab.
-
- Step 10
Since you have created an automation Get Order Details to collect
Order Amount
,Order Date
,Expected Delivery Date
andShipping Country
directly from the Excel file, you need to update the process condition which previously was dependent of Order Processing Form outputs.-
Click on Condition and choose Open Condition Editor.
-
In the Edit Branch Condition, select conditions :
Item Condition Value orderAmount
is less than 100000 shippingCountry
is equal to India shippingCountry
is equal to Germany Choose Apply to add the condition to the business process.
-
- Step 11
The different Forms of the process will need Inputs mapping from the automation Outputs.
-
Select the Auto Approval Notification and go to the Inputs :
- In the Order Amount field, choose the
orderAmount
from the Automation outputs. - In the Expected Delivery Date field, choose
expectedDeliveryDate
from the Automation outputs.
- In the Order Amount field, choose the
-
Select the Approval Form and go to the Inputs :
- In the Order Amount field, choose the
orderAmount
from the Automation outputs. - In the Expected Delivery Date field, choose
expectedDeliveryDate
from the Automation outputs.
- In the Order Amount field, choose the
-
Do the same for the Order Confirmation Notification.
-
Do the same for the Order Rejection Notification.
-
Save the Process.
You have successfully completed creating an automation in your process.
-
- Create the automation
- Create environment variable
- Add Excel activities
- Add input and output parameters
- Create a variable
- Looping through Excel sheet and searching for the order
- Link automation parameters with business process
- Test the automation
- Simplify the start form
- Update Process Condition
- Mapping forms of the process