/// <summary> /// Gets the option set text. /// </summary> /// <param name="entityName">Name of the entity.</param> /// <param name="attributeName">Name of the attribute.</param> /// <param name="optionSetValue">The option set value.</param> /// <returns>Result.</returns> public Result GetOptionSetText(string entityName, string attributeName, int?optionSetValue) { try { logSystem.CreateLog(System.Reflection.MethodBase.GetCurrentMethod().ToString() + " is called"); string AttributeName = attributeName; string EntityLogicalName = entityName; RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest { EntityFilters = EntityFilters.All, LogicalName = EntityLogicalName }; RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)xrmService.Execute(retrieveDetails); Microsoft.Xrm.Sdk.Metadata.EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata; Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals (attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata; Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata options = picklistMetadata.OptionSet; IList <OptionMetadata> OptionsList = (from o in options.Options where o.Value.Value == optionSetValue select o).ToList(); string optionsetLabel = (OptionsList.First()).Label.UserLocalizedLabel.Label; return(new Result(false, string.Empty, optionsetLabel, logSystem)); } catch (Exception ex) { return(new Result(true, MethodBase.GetCurrentMethod().ToString() + " : " + ExceptionHandler.HandleException(ex), null, logSystem)); } }
public static List <int> GetValues(this Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata optionSetMetadata) { return (( from option in optionSetMetadata.Options let value = option.Value where value.HasValue select value.Value ) .ToList()); }
public void GetGlobalOptionSetMetadata() { OrganizationRequest orgReq = null; Guid respId = Guid.NewGuid(); MRetrieveOptionSetResponse resp = new MRetrieveOptionSetResponse(); resp.BehaveAsDefaultValue(); resp.OptionSetMetadataGet = () => { return(new OptionSetMetadata()); }; MRetrieveResponse Rresp = new MRetrieveResponse(); Rresp.EntityGet = () => new Entity(); Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata M = null; BCrmServiceClient.AddResponse(typeof(RetrieveOptionSetRequest), resp); BCrmServiceClient.AddResponse(typeof(RetrieveRequest), Rresp); BCrmServiceClient.MockCrmCommandExecute(); M = crmaction.GetGlobalOptionSetMetadata("online"); orgReq = BCrmServiceClient.GetRequest(typeof(RetrieveOptionSetRequest)); Assert.IsNotNull(((RetrieveOptionSetRequest)orgReq).Name); }
/// <summary> /// Obtiene el texto del item de un campo picklist. /// </summary> /// <param name="entityName">NOmbre de la entidad donde se encuentra el campo</param> /// <param name="attributeName">Nombre del campo tipo picklist</param> /// <param name="optionSetValue">Valor del picklist </param> /// <param name="service">Objeto de servicio.</param> /// <returns></returns> public static string GetPickListText(string entityName, string attributeName, int optionSetValue, IOrganizationService service) { string entityLogicalName = entityName; RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest { EntityFilters = EntityFilters.All, LogicalName = entityLogicalName }; RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails); Microsoft.Xrm.Sdk.Metadata.EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata; Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata; Microsoft.Xrm.Sdk.Metadata.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); }
public List <CrmPicklist> ObtenerOptionSetEntidad(string NombreEntidad, string NombreAtributo) { List <CrmPicklist> lista = null; RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest { EntityFilters = EntityFilters.All, LogicalName = NombreEntidad }; RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)_servicio.Execute(retrieveDetails); Microsoft.Xrm.Sdk.Metadata.EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata; Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault( attribute => String.Equals(attribute.LogicalName, NombreAtributo, StringComparison.OrdinalIgnoreCase) ) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata; Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata options = picklistMetadata.OptionSet; IList <OptionMetadata> OptionsList = (from o in options.Options select o).ToList(); if (OptionsList != null) { lista = new List <CrmPicklist>(); foreach (OptionMetadata option in OptionsList) { CrmPicklist item = new CrmPicklist(); item.Id = option.Value; item.Nombre = option.Label.UserLocalizedLabel.Label; lista.Add(item); } } return(lista); }