Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve the optionset values for collection attaributes

(0) ShareShare
ReportReport
Posted on by 590

Hi Friends,

Background: I have more than 50 option list fields and more than 30 Two option Fields in the CRM form. I need to push the data to the CRM surface from custom asp.net application.I could able to get the optionset value for each fields by calling the service everytime.

Issue: I need to retrieve the optionset values for collection of fields.As performance will be degraded if I call 50 times.

Please Help me in this regard

With Regards,

Datat.G

*This post is locked for comments

  • Nuno Profile Picture
    Nuno 2,005 on at
    RE: Retrieve the optionset values for collection attaributes

    Hi Datta,

    Dictionary<Nullable<int>, string> RetriveOptionSetLabels(IOrganizationService service, string entityLogicalName, string optionSetLogicalName)

           {

               // Create the request

               RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest

               {

                   EntityLogicalName = entityLogicalName,

                   LogicalName = optionSetLogicalName

               };

               // Execute the request

               RetrieveAttributeResponse attributeResponse =

                   (RetrieveAttributeResponse)service.Execute(attributeRequest);

               // OptionSet metada

               PicklistAttributeMetadata metadata = attributeResponse.AttributeMetadata as PicklistAttributeMetadata;

               return metadata.OptionSet.Options.ToDictionary(x => x.Value, x => x.Label.UserLocalizedLabel.Label);

           }

    this function returns a dictionary whose entry is a keyValuePair<int, string> where the key is the value of the optionset and the value is the label of the optionset. As input it receives  the LogicalName of the entity and the LogicalName of the optionset.

  • DATTA GUNTURU Profile Picture
    DATTA GUNTURU 590 on at
    RE: Retrieve the optionset values for collection attaributes

    Hi Ben Hosking,

    Thank You Very much

    Could you please share some sample snippet

    With Regards,

    Datta.G

  • Suggested answer
    Hosk Profile Picture
    Hosk on at
    RE: Retrieve the optionset values for collection attaributes

    The first question is do you really need to show all 50 options sets, could you not hide some in a section or other un expanded section on your form.

    You could maybe create a .net method to select all the option sets at once on the onload and maybe store this in a collection or an array of arrays etc.  so you would only be doing one call to collect all the data at once.

  • MarkR_B Profile Picture
    MarkR_B 465 on at
    RE: Retrieve the optionset values for collection attaributes

    You need one call to the metadata webservice to obtain all the option set values and then one call to retrieve the data.

    I have done this client side before using the SDK.Metadata.js and then using the function

    SDK.Metadata.RetrieveAttribute("wsg_entityname", "wsg_optionsetfield", "00000000-0000-0000-0000-000000000000", true, function

    {

      //Loop through the records

      for (var i = 0; i < data.OptionSet.Options.length; i++) {                    

         var text = data.OptionSet.Options[i].Label.LocalizedLabels[0].Label;

         var value = data.OptionSet.Options[i].Value;

      }

    },

    function (error) { });

    If you are doing this server side you can use the C# SDK dll to call the API. I have blogged on this here mscrmdeveloper.wordpress.com/.../get-optionset-attribute-from-metadata.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans