In my previous articles, I have demonstrated how to set the default values for Lookup and Option Set field bound combo box controls in a Canvas Power App connected to a Leave Requests entity via the Common Data Service. In this article I demonstrate how an Option Set field bound combo box control can be programmatically updated.
The demonstration application is a sample ‘Leave Requests’ Canvas PowerApp. The app uses the Common Data Service (CDS) to connect to a Leave Requests entity in Microsoft Dynamics 365.
This article demonstrates the configuration of the buttons and combo box controls for the “Cover Person Response” and “Manager Response” Option Set fields on the Leave Request. These combo box controls were automatically added to the Edit Form when using Edit Fields to add the fields to the form. The properties and configuration of combo box controls added to a form in this way, differ to that of manually added and configured combo box and drop down controls.
On the Edit Form, I have added Accept and Reject buttons for the Cover Person Response and Approve and Decline buttons for the Manager Response. When clicked, these will programmatically update the corresponding Cover Person Response and Manager Response combo box controls. In addition, the Cover Person or Manager may also directly select a response using the combo box controls.
The following demonstrates how I have configured the Manager Response controls. The same configuration, with relevant changes of references to variables and controls, is used for the Cover Person Response.
The OnVisible event of the Edit Screen has been updated to include a step that initialises a context variable named “varManagerResponse” to the current value of the Manager Response for the Leave Request. This current value is obtained from the Default property of the Manager Response data card.
The Default property of the Manager Response data card is configured as shown below. This configuration is explained in a previous article.
The Update property of the Manager Response data card has been updated from “EditManagerResponse_DataCardCalue.Selected.Value” to “First([varManagerResponse]).Value”. This ensures that the current value of “varManagerResponse” is saved to the underlying record when a new or an existing Leave Request is saved. This syntax converts “varManagerResponse” to a table, and then retrieves the Value field of the first record of the table. This is an OptionSetValue field. Other variations of this syntax do not work.
The DefaultSelectedItems property, not to be confused with the Default property, of the Manager Response combo box control has been updated to: “[varManagerResponse]”. This ensures that the combo box control displays the current value of “varManagerResponse”. The Default property of the Manager Response combo box is not configured; i.e. it is blank.
The OnChange event of the Manager Response combo box control has been updated as shown below. This ensures that the value of “varManagerResponse” is updated whenever the Manager selects a Manager Response option using the combo box control.
The OnSelect event of the Approve button on the Manager Response data card has been configured as shown here:
The OnSelect event of the Decline button on the Manager Response data card has been configured as shown here:
These previous two formulas, set the Manager Response option set to either Accepted or Declined. The referenced ‘Leave Manager Response’ Option Set is provided by the underlying CDS data source to the Leave Requests entity. The Option Set Values are from the corresponding Dynamics 365 ‘Leave Manager Response’ Option Set.
Here is an example of a new Leave Request showing the default values for the Cover Person Response and Manager Response.
Here the Manager has clicked the Approve button to approve the Leave Request:
Here the Manager has clicked the Decline button decline the Leave Request:
Here the Manager has used the combo box control, to cancel the Leave Request:
In each of these cases, the Leave Request in Dynamics 365 has been successfully updated to the selected value when the Leave Request is saved.
Finally, in a completed app, you might consider hiding the combo box controls and showing just the buttons and might also consider using Flow to implement an approval process.