Exemplo n.º 1
0
        /// <summary>
        /// Gets the options set text on value.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="selectedValue">The selected value.</param>
        /// <returns>Option Set Value</returns>
        public static string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
        {
            try
            {
                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);
            }
            catch (Exception ex)
            {
                CustomServiceManagementPortalException customEx = new CustomServiceManagementPortalException("Error while getting time zone offset text.", ex);
                throw customEx;
            }
        }
        public static string GetOptionsSetTextForValue(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 = null;

            foreach (OptionMetadata oMD in optionList)
            {
                if (oMD.Value == selectedValue)
                {
                    selectedOptionLabel = oMD.Label.LocalizedLabels[0].Label.ToString();
                    break;
                }
            }
            return(selectedOptionLabel);
        }
        /// <summary>
        /// Gets the option sets.
        /// </summary>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <returns>Result.</returns>
        public Result GetOptionSets(string entityName, string attributeName)
        {
            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;

                foreach (OptionMetadata item in picklistMetadata.OptionSet.Options)
                {
                    ObjectCarrier.SetValue(item.Value.ToString(), item.Label.UserLocalizedLabel.Label);
                }

                return(new Result(false, string.Empty, ObjectCarrier.GetAllValues(), logSystem));
            }
            catch (Exception ex)
            {
                return(new Result(true,
                                  MethodBase.GetCurrentMethod().ToString() + " : " + ExceptionHandler.HandleException(ex),
                                  null, logSystem));
            }
        }
        /// <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));
            }
        }
Exemplo n.º 5
0
        /*
         * public DataTable GetPicklist()
         * {
         *  MetadataService metaService = CRMManager.GetMetaService();
         *
         *  RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
         *  attributeRequest.EntityLogicalName = "new_timeentry";
         *  attributeRequest.LogicalName = "new_billing";
         *  attributeRequest.RetrieveAsIfPublished = false;
         *
         *  RetrieveAttributeResponse response = (RetrieveAttributeResponse)metaService.Execute(attributeRequest);
         *  PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;
         *
         *  DataTable dt = new DataTable();
         *  dt.Columns.Add("Desc");
         *  dt.Columns.Add("Data");
         *
         *  dt.Rows.Add(new object[] { "", -1 });
         *
         *  foreach (Option o in picklist.Options)
         *  {
         *      DataRow dr = dt.NewRow();
         *      dr["Desc"] = o.Label.UserLocLabel.Label;
         *      dr["Data"] = o.Value.Value;
         *
         *      dt.Rows.Add(dr);
         *  }
         *
         *  return dt;
         * }
         */

        public String GetPicklistStr(IOrganizationService _Service, String EntityLogicalName, String LogicalName)
        {
            String rV = "";

            RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName     = EntityLogicalName,
                LogicalName           = LogicalName,
                RetrieveAsIfPublished = true
            };

            // Execute the request.
            RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)_Service.Execute(retrieveAttributeRequest);

            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();

            foreach (OptionMetadata oMD in optionList)
            {
                if (rV != "")
                {
                    rV += ";";
                }
                rV += oMD.Label.UserLocalizedLabel.Label;
                rV += "|";
                rV += oMD.Value.ToString();
            }

            return(rV);
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        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);
        }