Microsoft.Xrm.Data.PowerShell icon indicating copy to clipboard operation
Microsoft.Xrm.Data.PowerShell copied to clipboard

Create multiselect option set references

Open EdCallahan opened this issue 4 years ago • 1 comments

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

EdCallahan avatar Sep 30 '21 21:09 EdCallahan

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.

seanmcne avatar Oct 27 '21 18:10 seanmcne