Sam's Microsoft Dynamics 365 Blog

Wednesday, 5 September 2018

Insert and Get Value in MultiSelect Option Set Using C#

A new enhancement in Dynamics CRM is Multiselect Option set. We Insert Value using below code in Multiselect Option set.


Syntax:-  OptionSetValueCollection OPcollection = new OptionSetValueCollection() { new OptionSetValue(<value1>), new OptionSetValue(<value2>)};

Example:-
OptionSetValueCollection OPcollection = new OptionSetValueCollection() { new OptionSetValue(364760001), new OptionSetValue(364760002)};

Entity _account = new Entity("account");
_account.Attributes["name"] = "multiselect optionset test test";
_account.Attributes["new_myhobby"] = OPcollection;
var guiddata = _orgService.Create(_account);



We can Get Value using below code in Multiselect Option set.



Syntax:-  
OptionSetValueCollection OptionCollection = (OptionSetValueCollection)entity.Attributes["<FieldName>"];

foreach (var optionSetValue in OptionCollection)
  {
          OptionSetValue opVal = (OptionSetValue)optionSetValue;
  }

Example:-

OptionSetValueCollection OptionCollection = (OptionSetValueCollection)entity.Attributes["new_myhobby"];
foreach (var optionSetValue in OptionCollection)
   {
          OptionSetValue opVal = (OptionSetValue)optionSetValue;
   }


1 comment:

  1. Microsoft power apps is a suite of apps, data platform, connectors & services that facilitate a rapid app development environment.

    ReplyDelete

How to Get the Power Automate Flow Run URL Using Expressions

In many Power Automate projects, especially those involving approvals, error handling, or audit logs, it’s helpful to have a direct link to ...