Skip to Content

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.
You will learn
  • How to create an action to update data
  • How to use an action in your process
Created by
thecodester
December 12, 2024
Contributors
thecodester

Prerequisites

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.

  • Step 1

    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.

    1. Go to the SAP Build main page.

    2. Go to Control Tower, and then click Backend Configuration > Destinations.

      Add destination
    3. 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.

  • Step 2
    1. Go back to the SAP Build lobby, and click Connectors > Actions.

      Select Actions
    2. Choose Create.

      Create Actions
    3. 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.

    4. Enter OrderManagement-Actions for 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.

    5. 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
  • Step 3

    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.

    1. Click on the status field.

      This opens a dialog where you can set rules about the field.

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

      Set status
    3. Close the dialog, and click Save.

      Save
  • Step 4

    Let’s make sure everything is connected properly and test the action.

    1. Click the Test tab.

      Under Connectivity > Destination, select the destination CodeJamOrdersService from the dropdown options.

      Test
    2. Under the Test Input Values, enter 6c25e827-15c2-4e7f-be1a-89fb4304d4fa for the ID field.

      Test Input Values
    3. 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.

  • Step 5

    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.

    1. Click Release (top right).

      Release Actions
    2. 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
    3. Click Publish (top right).

      Publish

      Click Publish to confirm.

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

      Published Actions
  • Step 6

    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.

    1. Go back to your Purchase Approval project, and open the process.

      Make sure the Editable version is selected.

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

      Add action

      In the pop-up, choose Action.

      Invoke Action
    3. 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.

    4. 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 MyCAPDest in the Identifier field, and click Create.

      Destination variable identifiers cannot have spaces.

      Destination variable
    5. 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
    6. 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
    7. Click Save (upper right).

  • Step 7
    1. 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
    2. 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.

    3. 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.

  • Step 8

    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.

    1. Open your SAP Build Apps project.

    2. Open the My Orders page.

      My Orders
    3. In the component area, click Marketplace.

      Marketplace
    4. Search for basic table with data adapter.

      alt text

      Select the basic table, and click Install.

    5. On the UI canvas, under the Installed tab on the left, drag an instance of the basic table onto the canvas.

      alt text
    6. 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:

      JavaScript
      Copy
      systemVars.currentUser.email
      
      Customer

      Click Save twice.

      Click Save and Exit (top right.)

    7. Click the App Settings > Navigation tab.

      Click Add Item, and set the new item to the following.

      Icon Tab name Page
      credit card My Orders My Orders
    8. Click Save (upper right).

  • Step 9
    1. Click Preview, and then open up the preview for the app.

    2. Select the Notebook Basic 18, and add it to your cart.

    3. Go to the My Orders page and you will see your cart.

      Cart
    4. 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
    5. 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
    6. 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.

    7. 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.

Back to top