web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • MarkR_B Profile Picture
    465 on at

    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.

  • Suggested answer
    Hosk Profile Picture
    on at

    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.

  • DATTA GUNTURU Profile Picture
    590 on at

    Hi Ben Hosking,

    Thank You Very much

    Could you please share some sample snippet

    With Regards,

    Datta.G

  • Nuno Profile Picture
    2,005 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans