I have a Canvas App used for offline data capture that has been in use for about a year. It uses the "Dynamics 365" Connector, and I am now looking at migrating it to the new CDS Connector, but it's turning out to be a more complex transition than I had initially hoped. I'm having an issue with the Option Sets.
Option Sets and the Dynamics 365 Connector
The Canvas App has > 100 Combo Box controls for data capture. The items in these controls have Number values behind them which map to option set values in Dynamics/CDS. When capturing data with the Dynamics 365 Connector, i just need to reference the number value and it saves the option set in the record. This is ideal, as for the offline functionality, I don't need to cache 100+ option sets in the device.
Collect(MyCollection,{
new_myfield: 1
});
Patch('My Records', MyCollection)
CDS Connector
So with the CDS Connector, it wants me to reference that specific option set, which seems to be a data type of it's own in PowerApps. If I pass in a number, I get an error saying: "The type of this argument 'new_myfield' does not match the expected type 'OptionSetValue'. Found Type 'Number'. " . I can't create an enum or OptionSetValue using the number at runtime. With other Canvas Apps that have fewer Option Sets, I have successfully achieved the offline functionality with CDS connector by saving the Option Sets to the device, and then loading them into the choices into the combo boxes. If possible, I would like to avoid this, due to the high number of option sets.
What I'm looking for is a way to get write an Option Set Value to CDS from a number in PowerApps. There is a helpful solution in this post (https://powerusers.microsoft.com/t5/Building-Power-Apps/CDS-Two-Options-number-Singe-Check-Box/m-p/466463#M139622) that shows how to reference a CDS option set by its value. This doesn't work for me however, as the value must be wrapped in single quotes, and I need to dynamically reference the value using the selected item of the combo box.
The other two ways I'm approaching this are:
- Trying to cast the Number as an OptionSet when I capture the data to a collection. This doesn't seem to be achievable through PowerApps formulas.
or
- Getting the OptionSetValue from the number value when patching to the Data Source (as the device will always have connection, and thus be aware of the option sets when writing records to CDS). I'm trying to achieve this by using a Lookup() on the Option Set choices, but there is no attribute of the choices that I can use in the condition. The 'Value' keyword doesn't match the type of the Number
Collect(MyCollection,{
new_myfield:LookUp(Choices('My Option Set'), Value = 1)
});
I hope this makes some sense.
Any ideas on this would be greatly appreciated, though I realise I may have to resort to caching all of the option sets.
Thanks,
-Tadhg.