10 - Create Action Project to Post Data to CAP Service
Create an action project to update our CAP service and call the action from your process when the order is approved, as part of the SAP Build CodeJam.
Overview
You will learn
- How to create an action to update data
- How to use an action in your process
Prerequisites
Prerequisites
- You have completed the previous tutorial for the SAP Build CodeJam, Create Action to Get Data from SAP S/4HANA Cloud.
Steps
Intro
In the previous tutorial, you created and used an action to retrieve data from an SAP S/4HANA Cloud system.
In this tutorial, you will create another action, this time to connect to our CAP service and update an entity.
SAP Build Process Automation enables administrators to control which destinations โ and, therefore, which backend systems โ can be connected to processes during runtime.
You already created the destination for the CAP service because you needed it in the app. In this step, you will enable the destination to be used in your process.
Go to the SAP Build main page.
Go to Control Tower, and then click Backend Configuration > Destinations.

Add destination Click Add.

New destination Select your destination, CodeJamOrdersService.
Click Next.

Add On the second screen, keep the settings to allow the destination in All Environments.
Click Add Destination.

Add The destination will be added to the list of destinations that can be used within your processes for runtime.
Go back to the SAP Build lobby, and click Connectors > Actions.

Select Actions Choose Create.

Create Actions Select Live API > OData Destinations.

Select OData Select CodeJamOrdersService.

Select CodeJam Orders CodeJamOrdersService was already configured as a destination in the SAP BTP cockpit โ with the additional property
sap.applicationdevelopment.actions.enabledโ and hence is visible here.After selecting the destination, you will see a list of all the entities and all the API calls you can make.
Click Next.
Enter
OrderManagement-Actionsfor the project name and description.Click Create.

Project Name You will now see the operations available for this service, and you will need to decide which ones to expose.
In the Orders entity, you want to only update the status field. Hence, in the popup, you have to select the PATCH method of /Orders({ID}) API.
Select the Filter actions dropdown, filter option and choose PATCH.

Patch Update Now, under Orders there will appear just one API. Select it.
SAP Build Actions will open with the selected APIs. You can always go back and add additional APIs to expose.
Click Add.
The PATCH method to update the Orders entity is now selected and the action project is saved.

Path operation
Actions enable all kinds of customization to API calls – for example, to pre-set fields, enable additional inputs, set OData filters.
Here we will do something simple: whenever someone calls this API, the action will change the order status to APPROVED.
Click on the status field.
This opens a dialog where you can set rules about the field.

Open status Enable Static, and enter APPROVED for the value.

Set status Close the dialog, and click Save.

Save
Let’s make sure everything is connected properly and test the action.
Click the Test tab.
Under Connectivity > Destination, select the destination CodeJamOrdersService from the dropdown options.

Test Under the Test Input Values, enter
6c25e827-15c2-4e7f-be1a-89fb4304d4fafor the ID field.
Test Input Values Click Test.
Once the execution is successful, you should see 200: OK response.
If for some reason you entered an order ID that did not exist, the service will create it, and you will get a 201: OK status code.
If for some reason you entered a value that was not a GUID, you will get 400: BAD REQUEST or 404: NOT FOUND status code.
You will now release the action project to create a version and then publish this version in the action repository. It is this published action that you will connect to from your process.
Click Release (top right).

Release Actions In the release popup, enter the Release Notes of your choice.

Release Notes Click Release again, to confirm.
Notice the label has changed to Released.

Release status Click Publish (top right).

Publish Click Publish to confirm.
After publishing the actions project, notice the label has changed to Published.

Published Actions
You have already set up the approval form as part of the tutorial Add Approval Flow to Process.
Now, you will add the action so that if the order is approved, the action will update the status of the order.
Go back to your Purchase Approval project, and open the process.
Make sure the Editable version is selected.

Open project Click on the plus sign, + below the Approval Notification form.

Add action In the pop-up, choose Action.

Invoke Action Click Browse All Actions.

Select action In the Browse library pop-up, click Show Filter and then filter by the OrderManagementService action project.

Select action If you do not see the action you just publsihed, refresh the page.
Click Add next to the Patch API.
The action gets added and a side pane opens.

Action added with Side pane You will see a red warning icon. This is only because you still need to bind data to the action, for example, the order ID.
In the side pane, click the Destination variable dropdown, and choose Create Destination Variable.
A destination variable creates a way that you can deploy your process to different systems โ dev, test, production โ and assign different destinations for this action to each environment, without having to change the process itself.

Create variable Enter
MyCAPDestin the Identifier field, and click Create.Destination variable identifiers cannot have spaces.

Destination variable In the side pane, go to the Inputs tab.
Click in the ID field (this is one of the inputs defined in the action). You must bind which order to update.
Choose Process Inputs > Order ID.

Inputs tab Let’s do one more thing to make the process more efficient.
You updated the CAP service to change the status of our order when an approver approves the purchase. But you also want to update the order status when it is automatically approved.
Under the Approval Notification 1 form, click the plus sign, +.

Add go-to Select Controls and Events > Go-to-Step.

Go-to step Select the Update entity in Orders step.

Update orders Your process flow is update.

Process flow Click Save (upper right).
Click Release (top right).

Release after actions In the pop-up, for Release Notes, enter
Added Action to update Orders entity.Click Release.

Version comment Click Show project version.
Click Deploy.
Select the Public environment, and click Upgrade.

Select environment The triggers that will be deployed will be displayed. There is nothing to do here but confirm.
Click Deploy.

Deploy triggers Now you will see the environment variables for which you need to provide values.

Destinations Select the destination you created for accessing SAP S/4HANA and for the CAP service.
Click Deploy.
The status of the project changes to Deployed. Click the SAP logo at the upper left to return to SAP Build Lobby.
Go back to the SAP Build lobby.
Click the row for your process project, and then open the Versions tab.
Next to the version you just deployed, click the 3 dots and select Publish to Library.

Republish In the dialog, click Publish.
In order to better see the status of all my orders and cart, you will create in 5 minutes a page for checking the status of your orders.
Open your SAP Build Apps project.
Open the My Orders page.

My Orders In the component area, click Marketplace.

Marketplace Search for
basic table with data adapter.
alt text Select the basic table, and click Install.
On the UI canvas, under the Installed tab on the left, drag an instance of the basic table onto the canvas.

alt text In the Properties pane on the right, click Configure.
Select Orders.

Orders Click Properties, expand the Optional node.
Click the X next to Filter conditions.

Filter Select Object with properties, then Add Condition.
Set a condition where customer is equal to the following formula:
JavaScriptsystemVars.currentUser.email
Customer Click Save twice.
Click Save and Exit (top right.)
Click the App Settings > Navigation tab.
Click Add Item, and set the new item to the following.
Icon Tab name Page credit cardMy OrdersMy OrdersClick Save (upper right).
Click Preview, and then open up the preview for the app.
Select the Notebook Basic 18, and add it to your cart.
Go to the My Orders page and you will see your cart.

Cart Go to the Cart page, and you will see your cart with the item you just selected.
Select the business partner 100000, and then click Purchase.

Cart item The cart is sent to the process to be approved.

Purchase Go back to the My Orders page, and you will see that your cart now has a total โ 1570 โ and its status is now REQUESTED.

Requested Open your Inbox, and you can see the approval form.

Approval form Click Approve. The form disappears. Refresh the Inbox and you should see the notification form.

Notification form Click Submit. The process continues to update the status of the order, and then completes.
Check the process in the monitor tab (make sure you change the filter so it shows completed processes), and you can see all the steps completed – including the update of your order in our CAP service.

Process complete Back in your app, refresh the page and check the My Orders page again, and you will see the status of the order updated.

Order approved You will also notice that there is a new cart. Since you submitted the cart and changed it’s status to REQUESTED, the app no longer had a cart. And when the app returned to the home page, it created a new cart in the CAP service.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.