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)

Unable to retrieve option-set

(0) ShareShare
ReportReport
Posted on by 30
Hello Guys, 

I am facing a peculiar problem, where I am trying to retrieve the option-sets (Code snippet added below) but I get an error saying "Could not find optionset".
This only happens on production instance but it works fine on the developer instance. I have verified that the option-set I am trying to retrieve is present in that instance and the solution is published.


var retrieveOptionSetRequest = new RetrieveOptionSetRequest() { Name = optionName }; var response = (RetrieveOptionSetResponse)org.Execute(retrieveOptionSetRequest);

Any idea what could have caused this issue?

Thanks

Danish Aalam

*This post is locked for comments

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Please make sure optionset is from same publisher, it may be it has the same display name but having a different prefix ??

  • ashlega Profile Picture
    34,477 on at

    Maybe that option set in production has slightly different schema name(upper case vs lower case, for example)?

  • Danish Aalam Profile Picture
    30 on at

    I even tried retrieving out of the box option sets like "customertypecode" but unable to retrieve them from this particular instance.

  • Danish Aalam Profile Picture
    30 on at

    I am copying the schema name from CRM solution to refer the option-set. The code doesn't work for the out of the box option-sets as well.

  • Verified answer
    Nuno Profile Picture
    2,005 on at

    Hi,

    The RetrieveOptionSetRequest message is used to retrieve  a global option sets. The option set you are trying to retrieve is also an global one in the production system?

  • Suggested answer
    jestuder Profile Picture
    158 on at

    Here are some methods I use to get option set by label or by value.  There is 2 for local options set and 2 for global option set.  1 returns the label and one returns the value based on what you are trying to accomplish.  Hope this helps with what you are looking for.  If it does please high the verified answer button.  Thanks.

    public string GetLocalOptionSetLabel(string entityLogicalName, string optionSetName, int value, IOrganizationService service)
            {
                XrmServiceContext crmContext = new XrmServiceContext(service);
                RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
                {
                    EntityFilters = EntityFilters.All,
                    LogicalName = entityLogicalName
                };
                RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
                EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
                PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => string.Equals(attribute.LogicalName, optionSetName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;
                OptionSetMetadata options = picklistMetadata.OptionSet;
                IList<OptionMetadata> OptionsList = (from o in options.Options
                                                     where o.Value.Value == value
                                                     select o).ToList();
                string optionsetLabel = (OptionsList.First()).Label.UserLocalizedLabel.Label;
                return optionsetLabel;
            }

    public string GetGlobalOptionSetLabel(string optionSetName, int value, IOrganizationService service)
            {
                XrmServiceContext crmContext = new XrmServiceContext(service);
                string optionSetLabel = "";
                RetrieveOptionSetRequest retrieveOptionSetRequest = new RetrieveOptionSetRequest { Name = optionSetName };
                RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)crmContext.Execute(retrieveOptionSetRequest);
                OptionSetMetadata retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;
                OptionMetadata[] optionArray = retrievedOptionSetMetadata.Options.ToArray();
                foreach (var option in optionArray)
                {
                    if(option.Value.Value == value)
                    {
                        optionSetLabel = option.Label.LocalizedLabels[0].Label;
                    }
                }
                return optionSetLabel;
            }

            public int GetLocalOptionSetValue(string entityLogicalName, string optionSetName, string label, IOrganizationService service)
            {
                XrmServiceContext crmContext = new XrmServiceContext(service);
                RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
                {
                    EntityFilters = EntityFilters.All,
                    LogicalName = entityLogicalName
                };
                RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
                EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
                PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => string.Equals(attribute.LogicalName, optionSetName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;
                OptionSetMetadata options = picklistMetadata.OptionSet;
                IList<OptionMetadata> OptionsList = (from o in options.Options
                                                     where o.Label.UserLocalizedLabel.Label == label
                                                     select o).ToList();
                int optionsetValue = (OptionsList.First()).Value.Value;
                return optionsetValue;
            }

            public int GetGlobalOptionSetValue(string optionSetName, string label, IOrganizationService service)
            {
                XrmServiceContext crmContext = new XrmServiceContext(service);
                int optionSetValue = 0;
                RetrieveOptionSetRequest retrieveOptionSetRequest = new RetrieveOptionSetRequest { Name = optionSetName };
                RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)crmContext.Execute(retrieveOptionSetRequest);
                OptionSetMetadata retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata;
                OptionMetadata[] optionArray = retrievedOptionSetMetadata.Options.ToArray();
                foreach (var option in optionArray)
                {
                    if (option.Label.LocalizedLabels[0].Label == label)
                    {
                        optionSetValue = option.Value.Value;
                    }
                }
                return optionSetValue;
            }


  • Verified answer
    Danish Aalam Profile Picture
    30 on at

    Hello,

    I thank all of you for your responses. I figured it yesterday that the option-set was not global. That was the reason I was unable to retrieve them. I made the option-set global and now it works like a charm.

    Thanks

    Danish Aalam

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