Tuesday, July 16, 2013

Display label of option set based on value

Display label of option set based on value


string GlobaloptionsetText = GetCRMOptionSetLabel(service, entity.LogicalName, "new_rating", irating);


   private string GetCRMOptionSetLabel(IOrganizationService service, string entityname, string optionsetname, int value)
        {
            Microsoft.Xrm.Sdk.Messages.RetrieveAttributeRequest reqOptionSet = new Microsoft.Xrm.Sdk.Messages.RetrieveAttributeRequest();
            reqOptionSet.EntityLogicalName = entityname;
            reqOptionSet.LogicalName = optionsetname;
            Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse resp = (Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse)service.Execute(reqOptionSet);
            Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata opdata = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)resp.AttributeMetadata;
            var option = opdata.OptionSet.Options.FirstOrDefault(o => o.Value == value);

            return option.Label.LocalizedLabels.FirstOrDefault().Label;
        }

No comments:

Post a Comment

Power Automate Optimization: Filter Rows vs Trigger Conditions - When and Why to Use Each

Filter Rows vs Trigger Conditions in Power Automate Filter Rows vs Trigger Conditions in Power Automate Why your flow...