4. Edit Back End Logic with Joule

4. Edit Back End Logic with Joule

  1. Select A_SalesOrder entity by selecting the title.

  2. Select Add Logic.

    4_E2E_BuildCode-2
  3. Leave everything by the default value and select Add.

    4_E2E_BuildCode-3
  4. Select the Standard Event Read.

  5. Select Phase Before.

  6. Go to Open Code Editor > Application Logic.

    4_E2E_BuildCode-6
  7. This will open Joule again to create the logic for us. Notice how the prompt defaults to: /cap-app-logic #srv/code/a_salesorder-logic.js

    Note: If the prompt does not default to the preceding value, copy and paste it into the prompt box before proceeding.

    4_E2E_BuildCode-7
  8. Use the following prompt in Joule to create a backend logic:

Create an event handler that connects to the external service S4HANA_Joule_SalesOrder using cds connect to. The handler should retrieve the A_SalesOrder entity from this external service. If the request.query.SELECT object exists, modify the query to sort the results by the CreationDate field in descending order and limit the results to the top 300 records. Ensure that the query modifications are applied directly to the request.query object, and use the modified query to retrieve the data from the external service.

  1. Select Generate.

    4_E2E_BuildCode-9
  2. Joule created the following logic:

    • Order results by Sales Order Creation Date descending.
    • Limit results to 300 records.
  3. Accept the code created by Joule.

    • Joule may generate different codes for the same prompt. If the code for the backend logic differs but achieves the same result, you can ignore the variation and continue working on the exercise.

    4_E2E_BuildCode-11
  4. The logic of the A_SalesOrder service has been updated.

    4_E2E_BuildCode-12