This blog is part of the series Visual Builder Cloud Service Learning Path. In the previous lesson, we designed the process we will use in our application. If you don't have it, you can download the process and the VBCS application and import them into your environments. We assume that you've named the process Expense Approvals and have already started the process in Test mode as described in the last chapter.
In this tutorial, we'll look at how to start a process from our ExpenseReport VBCS application and pass in the required information as part of the REST call. This entails the following steps:
- Registering an Alias for the process in VBCS. This will allow us to reference the process without having to make changes to our code when we publish our application.
- Calling the Start Process REST API passing in the info that we marked as required on the Start message in the process. PCS needs to know the version and mode of the application so that it can correctly configure the REST URL to call back into VBCS business object REST endpoints. It also needs to have the name and id of the expense report item so we can correctly configure the Task List in VBCS.
- Storing the identifier of the the process we started back in the VBCS business object. This is so we can associate a specific expense report record with the correct instance of the approval process and show the right tasks for that record when we view its Edit screen.
Registering the Process Alias
- In the Expense Report application in VBCS, click the Processes tab on the left. Then click the + sign at the top of the Processes tab.
- Select ExpenseApproval in the list, click Add, then click Close.
If it doesn't appear, make sure Include test instances in selected and you have activated the process in Test mode in PCS as described in the last chapter. If it still doesn't show, try refreshing VBCS and opening the Register Deployed Process window again.
Editing the CreateExpenseReport Action Chain to Start the Process
Now we need to edit the create expense report action chain to do the following:
- Save the Expense Report record
- Save the record in a temporary action chain variable
- Call the Start Process REST endpoint, passing in the required attributes
- Store the processInstanceId from the response to the Start Process call into our temporary variable
- Call the PATCH REST endpoint for the Expense Report record we just created, passing in our temporary variable
So let's do this now.
- In the Web Apps window, open expenses > flows > main > CreateExpenseReport.
- Open the Actions tab, click the createExpenseReport action.
- Click the Variables tab in the left of the Action Chain Editor. Add a variable called patchPayload of type updateExpenseReportRequest.
- Click the Action Chain tab in the left of the Action Chain Editor to view the steps of the action chain again. Drag an Assign Variables action to the success path on the far left of the action chain.
- In the Property Inspector, click Assign next to Variables.
- Map Results > createExpenseReport > body to Action Chain > patchPayload. Click Save.
- Drag a Start Process action under the Assign Variables action you just added. In the Property Inspector, click Select Process.
- Select Process Alias > ExpenseApproal > Receive Message
- In the Property Inspector, click startPayload under Input Parameters.
- Map id and name from Results > createExpenseReport > body on the left to id and name from Parameters > startPayload on the right. Click Save.
- Drag an Assign Variables action under the Start Process action that you just added. In the Property Inspector, click Assign next to Variables. Map Action Chain > Results > startProcess1 > content > id to Action Chain > patchPayload > processDefId on the right.
- Drag a Call REST Endpoint action under the Assign Variables action that you just added. Click Select Endpoint.
- Select the PATCH /ExpenseReprort/{ExpenseReportId} endpoint.
- Under Input Parameters in the Property Inspector, click ExpenseReport_Id. Map Action Chain > Results > createExpenseReport > body > id on the left to Parameters > ExpenseReport_Id on the right. Click Save.
- Under Parameters in the Property Inspector, click body. Map Action Chain > patchPayload on the left to Parameters > body on the right. Click Save.
- Close the CreateExpenseReportChain tab.
- In the Page Designer for the CreateExpenseReport page, change the display text of the Save button to Submit.
- Test the application by entering a new expense report. In the PCS Test window, you will now see an instance in the Running Instances list.
In the next chapter, we will add a Task List to the application.