Get Picklist ,Status , State Lable Value

Get OptionSet Lable Value

function call : 
GetOptionsSetTextOnValue(service, Opportunity.EntityLogicalName, “opportunityratingcode”, ((OptionSetValue)_entityOpp.Attributes["opportunityratingcode"]).Value);

 private string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
        {

            RetrieveAttributeRequest retrieveAttributeRequest = new
            RetrieveAttributeRequest
            {

                EntityLogicalName = entityName,

                LogicalName = attributeName,

                RetrieveAsIfPublished = true

            };
            // Execute the request.
            RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
            // Access the retrieved attribute.

            Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)

            retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.
            OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
            string selectedOptionLabel = string.Empty;
            foreach (OptionMetadata oMD in optionList)
            {
                if (oMD.Value == selectedValue)
                {
                    selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label;

                }

            }
            return selectedOptionLabel;
        }

Get State Lable Value

private string GetStateTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
        {

            RetrieveAttributeRequest retrieveAttributeRequest = new
            RetrieveAttributeRequest
            {

                EntityLogicalName = entityName,

                LogicalName = attributeName,

                RetrieveAsIfPublished = true

            };
            // Execute the request.
            RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
            // Access the retrieved attribute.

            AttributeMetadata attrMetadata =
        (AttributeMetadata)retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.

            // Cast the AttributeMetadata to StatusAttribute data 
            StateAttributeMetadata statusAttrMetadata =
                (StateAttributeMetadata)attrMetadata;

            string selectedOptionLabel = string.Empty;
            foreach( StateOptionMetadata statusMeta in 
    statusAttrMetadata.OptionSet.Options)
            {
                if (statusMeta.Value == selectedValue)
                {
                    selectedOptionLabel = statusMeta.Label.UserLocalizedLabel.Label;

                }

            }
            return selectedOptionLabel;
        }

Get Status Lable Value

private string GetStatusTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
        {

            RetrieveAttributeRequest retrieveAttributeRequest = new
            RetrieveAttributeRequest
            {

                EntityLogicalName = entityName,

                LogicalName = attributeName,

                RetrieveAsIfPublished = true

            };
            // Execute the request.
            RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
            // Access the retrieved attribute.

            AttributeMetadata attrMetadata =
        (AttributeMetadata)retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.

            // Cast the AttributeMetadata to StatusAttribute data 
            StatusAttributeMetadata statusAttrMetadata =
                (StatusAttributeMetadata)attrMetadata;

            string selectedOptionLabel = string.Empty;
            foreach (StatusOptionMetadata statusMeta in
    statusAttrMetadata.OptionSet.Options)
            {
                if (statusMeta.Value == selectedValue)
                {
                    selectedOptionLabel = statusMeta.Label.UserLocalizedLabel.Label;

                }

            }
            return selectedOptionLabel;
        }
This entry was posted in MS Dynamic CRM 2011. Bookmark the permalink.

9 Responses to Get Picklist ,Status , State Lable Value

  1. I just wanted to inform you how much my spouse and i appreciate everything you’ve shared to help improve lives of people in this subject material. Through your current articles, I’ve gone from just a newbie to a professional in the area. It’s truly a gratitude to your endeavours. Thanks

  2. Many thanks for your time to have put these things together on this web site. Josh and i also very much loved your insight through the articles over certain things. I am aware that you have many demands with your schedule and so the fact that you took all the time like you did to steer people really like us through this article is actually highly loved.

  3. The suggestions you provided here are rather precious. Rrt had been such a fun surprise to see that looking forward to me once i woke up now. They are generally to the point as well as simple to learn. Thank you for the valuable ideas you have shared here.

  4. I simply wanted to let you know how much my partner and i appreciate everything you’ve provided to help increase the value of the lives of people in this theme. Through your own articles, I’ve gone from just a newcomer to a skilled in the area. It can be truly a honor to your initiatives. Thanks

  5. I'm not old says:

    I couldn’t have really asked for a more rewarding blog. You happen to be ever present to present excellent guidance, going on to the point for quick understanding of your target audience. You’re truly a terrific pro in this subject matter. Thanks a lot for always being there for people like me.

  6. The suggestions you provided here are incredibly valuable. Rrt had been such a fun surprise to get that awaiting me after i woke up now. They are often to the point plus easy to grasp. Thank you so much for the valuable ideas you have shared above.

  7. gold jewelry says:

    The guidelines you discussed here are very useful. Rrt had been such an entertaining surprise to have that awaiting me when I woke up today. They are always to the point plus easy to understand. Thanks a ton for the innovative ideas you’ve shared above.

  8. Say thanks a lot for your time and energy to have decided to put these things together on this site. John and that i very much valued your ideas through the articles in certain things. I understand that you have a number of demands on your own program hence the fact that you took the maximum amount of time as you did to help people like us by way of this article is also highly liked.

  9. We so appreciate your site post. You can find lots of methods we could put it to decent use while having little or no effort with time and capital. Thank you so much regarding helping make the post reply many problems we have got before now.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>