seanmcne / Microsoft.Xrm.Data.PowerShell

This module uses the CRM connection from Microsoft.Xrm.Tooling.CrmConnector.Powershell and provides common functions to create, delete, query, and update data as well as functions for common tasks such as publishing, and manipulating System & CRM User Settings, etc. The module should function for both Dynamics CRM Online and On-Premise environment.
203 stars 65 forks source link

Create multiselect option set references #486

Open EdCallahan opened 3 years ago

EdCallahan commented 3 years ago

It would be nice to have New-CrmOptionSetValue be extended to handle multiselect option sets, which are setup in D365 to allow multiple options to be selected in the same record/field. Or to have a new function like "New-CrmOptionSetValues".

Currently, even when assigning only one value, the following will fail if the option set is configured to be multiselect:

$fields = @{ 'fieldname' = $(New-CrmOptionSetValue -Value 'fieldvalue') }
New-CrmRecord -conn $CrmClient -EntityLogicalName Entity -Fields $fields

I have this workaround, but handling it within a function call would be nice:

$optionSets = @(New-CrmOptionSetValue -Value 'fieldvalue')
$optionSetCollection = New-Object -TypeName "Microsoft.Xrm.Sdk.OptionSetValueCollection"
$null = $optionSetCollection.AddRange($optionSets)

$fields = @{ 'fieldname' = $optionSetCollection }
New-CrmRecord -conn $CrmClient -EntityLogicalName Entity -Fields $fields
seanmcne commented 3 years ago

Interesting, do you have any thoughts about how this might work well either with its own multi select optionset cmdlet or with the existing one? Multi-select seems really specific and I'm not sure if it would work best to have its own cmdlet or somehow combine them into one.