Пример #1
0
        public CRMPicklist CRMGetStateStatus(CRMPicklist picklist)
        {
            OrganizationServiceProxy _serviceProxy;

            using (_serviceProxy = GetCRMConnection())
            {
                try
                {
                    RetrieveAttributeRequest retrieveAttributeStateRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName       = "statecode",
                    };
                    RetrieveAttributeResponse retrieveAttributeStateResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeStateRequest);

                    RetrieveAttributeRequest retrieveAttributeStatusRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName       = "statuscode"
                    };
                    RetrieveAttributeResponse retrieveAttributeStatusResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeStatusRequest);

                    StateAttributeMetadata  state  = (StateAttributeMetadata)retrieveAttributeStateResponse.AttributeMetadata;
                    StatusAttributeMetadata status = (StatusAttributeMetadata)retrieveAttributeStatusResponse.AttributeMetadata;


                    List <CRMPicklistOption> options = new List <CRMPicklistOption>();
                    foreach (StatusOptionMetadata o in status.OptionSet.Options)
                    {
                        OptionMetadata s = state.OptionSet.Options.Where(p => p.Value.Value == o.State.Value).First();

                        CRMPicklistOption option = new CRMPicklistOption();
                        option.PicklistValue       = o.Value.HasValue ? o.Value.Value : 0;
                        option.PicklistLabel       = o.Label.UserLocalizedLabel.Label;
                        option.PicklistParentLabel = s.Label.UserLocalizedLabel.Label.ToString();
                        option.PicklistParentValue = s.Value.HasValue ? s.Value.Value : 0;
                        options.Add(option);
                    }
                    picklist.Picklist = options;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(picklist);
        }
Пример #2
0
        public CRMPicklist CRMGetPicklist(CRMPicklist picklist)
        {
            OrganizationServiceProxy _serviceProxy;

            using (_serviceProxy = GetCRMConnection())
            {
                try
                {
                    RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName       = picklist.AttributeLogicalName
                    };
                    RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeRequest);

                    PicklistAttributeMetadata pick = (PicklistAttributeMetadata)retrieveAttributeResponse.AttributeMetadata;

                    StateAttributeMetadata a = new StateAttributeMetadata();


                    List <CRMPicklistOption> options = new List <CRMPicklistOption>();
                    foreach (OptionMetadata o in pick.OptionSet.Options)
                    {
                        CRMPicklistOption option = new CRMPicklistOption();
                        option.PicklistValue = o.Value.HasValue ? o.Value.Value : 0;
                        option.PicklistLabel = o.Label.UserLocalizedLabel.Label;
                        options.Add(option);
                    }
                    picklist.Picklist = options;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(picklist);
        }
        public CRMPicklist CRMGetStateStatus(CRMPicklist picklist)
        {
            OrganizationServiceProxy _serviceProxy;

            using (_serviceProxy = GetCRMConnection())
            {
                try
                {
                    RetrieveAttributeRequest retrieveAttributeStateRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName = "statecode",
                    };
                    RetrieveAttributeResponse retrieveAttributeStateResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeStateRequest);

                    RetrieveAttributeRequest retrieveAttributeStatusRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName = "statuscode"
                    };
                    RetrieveAttributeResponse retrieveAttributeStatusResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeStatusRequest);

                    StateAttributeMetadata state = (StateAttributeMetadata)retrieveAttributeStateResponse.AttributeMetadata;
                    StatusAttributeMetadata status = (StatusAttributeMetadata)retrieveAttributeStatusResponse.AttributeMetadata;


                    List<CRMPicklistOption> options = new List<CRMPicklistOption>();
                    foreach (StatusOptionMetadata o in status.OptionSet.Options)
                    {
                        OptionMetadata s = state.OptionSet.Options.Where(p => p.Value.Value == o.State.Value).First();

                        CRMPicklistOption option = new CRMPicklistOption();
                        option.PicklistValue = o.Value.HasValue ? o.Value.Value : 0;
                        option.PicklistLabel = o.Label.UserLocalizedLabel.Label;
                        option.PicklistParentLabel = s.Label.UserLocalizedLabel.Label.ToString();
                        option.PicklistParentValue = s.Value.HasValue ? s.Value.Value : 0; 
                        options.Add(option);
                    }
                    picklist.Picklist = options;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return picklist;
        }
        public CRMPicklist CRMGetPicklist(CRMPicklist picklist)
        {
            OrganizationServiceProxy _serviceProxy;

            using (_serviceProxy = GetCRMConnection())
            {
                try
                {
                    RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName = picklist.AttributeLogicalName
                    };
                    RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeRequest);

                    PicklistAttributeMetadata pick = (PicklistAttributeMetadata)retrieveAttributeResponse.AttributeMetadata;

                    StateAttributeMetadata a = new StateAttributeMetadata();
                    

                    List<CRMPicklistOption> options = new List<CRMPicklistOption>();
                    foreach (OptionMetadata o in pick.OptionSet.Options)
                    {
                        CRMPicklistOption option = new CRMPicklistOption();
                        option.PicklistValue = o.Value.HasValue ? o.Value.Value : 0;
                        option.PicklistLabel = o.Label.UserLocalizedLabel.Label;
                        options.Add(option);
                    }
                    picklist.Picklist = options;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return picklist;
        }
        private Property SetGetPicklistOptionProperties(Property prop, CRMPicklistOption task)
        {
            switch (prop.Name.ToLower())
            {
                case "picklistlabel":
                    prop.Value = task.PicklistLabel;
                    break;
                case "picklistvalue":
                    prop.Value = task.PicklistValue;
                    break;
                case "picklistparentlabel":
                    prop.Value = task.PicklistParentLabel;
                    break;
                case "picklistparentvalue":
                    prop.Value = task.PicklistParentValue;
                    break;
            }

            return prop;
        }