optionset vlaue Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/optionset-vlaue/ Microsoft Dynamics CRM . Microsoft Power Platform Thu, 20 Mar 2014 13:16:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.1 https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/cropped-Microsoftdynamics365-blogs.png?fit=32%2C32 optionset vlaue Archives - Microsoft Dynamics 365 Blog http://microsoftdynamics.in/category/optionset-vlaue/ 32 32 176351444 Get Optionset Value and Lable Using Plugin (OptionSet Label / text ) In MSCRM 2011 , 2013 http://microsoftdynamics.in/2014/03/20/get-optionset-value-and-lable-using-plugin-optionset-label-text-in-mscrm-2011-2013/ Thu, 20 Mar 2014 13:16:00 +0000 http://microsoftdynamics.in/2014/03/20/get-optionset-value-and-lable-using-plugin-optionset-label-text-in-mscrm-2011-2013/                      using System; using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Runtime.Serialization;using System.ServiceModel;using Microsoft.Xrm.Client;using Microsoft.Xrm.Portal;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Query;using Microsoft.Xrm.Sdk.Messages;using Microsoft.Xrm.Sdk.Metadata; namespace ClassLibrary2{    public class Class1 : IPlugin    {        public void Execute(IServiceProvider serviceProvider)        {            IPluginExecutionContext context = (IPluginExecutionContext)            serviceProvider.GetService(typeof(IPluginExecutionContext));            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);             // Retrive All Vlaue From Single Record on which pluging is...

The post Get Optionset Value and Lable Using Plugin (OptionSet Label / text ) In MSCRM 2011 , 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>

 using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

namespace ClassLibrary2
{
    public class Class1 : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            // Retrive All Vlaue From Single Record on which pluging is fired
             new_teston test = (new_teston)service.Retrieve(new_teston.EntityLogicalName, context.PrimaryEntityId, new ColumnSet(true));

            // “s” Contain OptionSet Value ( s = 1 , 2 , 3 , …)
             int s = Convert.ToInt32(((OptionSetValue)test.Attributes[“new_optionset”]).Value);

            // Function For Retriving OptionSet Label Through Value of “s”
             string ss = GetPickListText(new_teston.EntityLogicalName, “new_optionset”, s, service);

             new_testto tes = new new_testto();
             tes.new_name = ss;

            service.Create(tes);
        }

        public string GetPickListText(string entityName, string attributeName, int optionSetValue, IOrganizationService service)
         {
             string AttributeName = attributeName;
             string EntityLogicalName = entityName;

            RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest();
            retrieveDetails.EntityFilters = EntityFilters.All;
            retrieveDetails.LogicalName = EntityLogicalName;

            RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
             EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;

            PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as PicklistAttributeMetadata;

            OptionSetMetadata options = picklistMetadata.OptionSet;
             IList<OptionMetadata> picklistOption = (from o in options.Options where o.Value.Value == optionSetValue select o).ToList();
             string picklistLabel = (picklistOption.First()).Label.UserLocalizedLabel.Label;

             return picklistLabel;

        }

     }

}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

The post Get Optionset Value and Lable Using Plugin (OptionSet Label / text ) In MSCRM 2011 , 2013 appeared first on Microsoft Dynamics 365 Blog.

]]>
2827