In this article, I demonstrate how easy it is to set the default value for a ComboBox control associated with a Dynamics 365 Option Set field in a Canvas PowerApp. The approach demonstrated eliminates the need to change the bound ComboBox control to an unbound DropDown control. Because of this, it also eliminates the need to use the Patch function for saving the record.
The demonstration application is a sample ‘Leave Requests’ Canvas PowerApp. The app uses the Common Data Service (CDS) connector to access a Leave Requests entity in Microsoft Dynamics 365.
The following image shows the app’s Edit Form open for adding a new Leave Request. There are no default values configured for any of the Option Set field controls on the form; i.e. Leave Type, Cover Person Response, Manager Response and Status Reason.
These ComboBox controls are bound to the corresponding single-select Option Set fields from the Microsoft Dynamics 365 ‘Leave Requests’ entity.
The automatically generated formulas for the Default property of each of these Option Set field’s corresponding Data Cards are as follows:
For an existing Leave Request, “ThisItem.' Manager Response'”, returns the currently selected Manager Response option such as ‘Approved’ or ‘Declined’. However, for a new Leave Request, “ThisItem.' Manager Response'” does not return a value. The is also the case for the corresponding ‘Leave Type’, ‘Cover Person Response’ and ‘Status Reason’.
The desired default value for Manager Response is ‘Pending’. Attempting to change the Default property formula, as shown in the following image, causes an “Expected OptionSetValue” error to be displayed. This error occurs an Option Set value is required, but “Pending” is a Text value.
The approach is to use the corresponding Option Set enumeration provided by the underlying CDS ‘Leave Requests’ data source.
In this example, the Display Name of the Dynamics 365 Option Set used for Manager Response is “Leave Manager Response”. Typing “‘Leave Manager Response’.” causes a list of matching enumerated options to be displayed below the formula. You may then select an option from the list or type the option Label such as “Pending”; i.e. “‘Leave Manager Response’.Pending”.
The following image shows the updated formulas for the Default property of the other Option Set field related Data Cards on the Edit Form. The formula for Leave Type is unchanged because the User selects the Leave Type for themselves. The formula for Cover Person Response also considers whether a Cover Person is selected.
As a result, when adding a new Leave Request, the default values for Cover Person Response, Manager Response and Status Reason are now set to the required default Option Set values.
Completing the other fields clicking Accept, results in the successful creation of the new Leave Request.
In conclusion, as shown in this example, it is easy to set the default value for an Option Set field in a Canvas App. The approach does not require the replacement of a bound ComboBox control with an unbound DropDown control and therefore does not require the use of the Patch function when saving the record.