Personalized Community is here!
Quickly customize your community to find the content you seek.
‘Better Together’ Integration forum available
We're launching a how-to forum where you can learn and engage about how Dynamics 365 integrates with other Power Platform products.
Read about Better Together forum
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 1 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
A couple of weeks ago I shared a solution for supporting multiselect option sets on a PowerApps Portal (they aren’t currently supported out-of-the-box), however it only worked for creating new records. If you want it to work for updating existing records, there is a bit more work to do, but thankfully not that much!
In my previous post the technique I explained involved adding a text attribute to the entity, saving a comma-delimited list of values to Dynamics, and then using a plugin to parse the text field and set the actual multiselect option set field. This works great when you are creating new records.
The challenge for updating records is that you need to retrieve the existing value from the database to properly prefill the user interface, and you also have to handle situations where the field may be changed directly in Dynamics 365.
A straight-forward change to the plugin code will allow us to synchronize our multiselect option set with our text field. The updated code is shown below in bold:
public void Execute(IServiceProvider serviceProvider)
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var entity = context.InputParameters["Target"] as Entity;
OptionSetValueCollection colours = new OptionSetValueCollection();
foreach (var option in entity.GetAttributeValue("ec_favouritecolourportal").Split(','))
entity["ec_favouritecolour"] = colours;
else if (entity.Attributes.ContainsKey("ec_favouritecolor"))
entity["ec_favouritecolourportal"] = string.Join(",", entity.GetAttributeValue("ec_favouritecolour").Select(o => o.Value.ToString()));
The other key is that you need to register the plugin to run on update of your records as well (in the previous example, it only needed to run on create).
This will ensure that when the multiselect option set field changes, those changes are synchronized to the text field. This will allow us to show the already selected options in the Portal, even if a change is made directly in Dynamics.
var favouriteColour = $('#ec_favouritecolourportal');
var multiselect = $('<select multiple><option value="948180000">Red</option><option value="948180001">White</option></select>');
As you can see, only one additional line is required (jQuery does a lot of the heavy lifting for us). All we need to do is read in the value from the text field (which should be updated via the plugin), split by the comma, and set the value (jQuery expects an array of values to set a multiselect option set).
As opposed to trying to keep the text field synchronized, I thought that there may be an easier technique to get the current value of the multiselect option set. Even though they aren’t supported on Entity Forms or Web Forms, I thought that perhaps there might be another area that does support them. I tried:
So, in the end, the plugin technique was the best I could come up with.
The post PowerApps Portals: Multiselect Option Set – Part 2 appeared first on Engineered Code.
Business Applications communities