Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Drayton 29 posts 49 karma points
    Oct 26, 2011 @ 16:15
    Peter Drayton
    0

    Added a Custom Prevalue Type, but it won't save.

    Hi,

    I have created a Custom Prevalue Type based on http://www.nibble.be/?p=86

        public class GetValuesFromMailChimp : FieldPreValueSourceType
        {
     
            public GetValuesFromMailChimp()
            {
                this.Id = new Guid("35C2053E-CBF7-4793-B27C-6E97B7671A2D");
                this.Name = "Get values from MailChimp";
                this.Description = "Getting values from MailChimp";
            }
     
            public override List<PreValue> GetPreValues(Field field)
            {
                List<PreValue> result = new List<PreValue>();
     
                try
                {            
                    int sort = 0;
                    string[] values = GetListSegments();
                    foreach (string value in values)
                    {
                        if (!string.IsNullOrEmpty(value.Trim()))
                        {
                            PreValue pv = new PreValue();
                            pv.Id = sort;
                            pv.Value = value;
                            if (field != null)
                            {
                                pv.Field = field.Id;
                            }
                            pv.SortOrder = sort;
                            result.Add(pv);
                            sort++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Umbraco.Forms.Data.LogHelper.Error(
                        "Get values from MailChimp: " + ex.ToString());
                }

                return result;
            }

            public override List<Exception> ValidateSettings()
            {
                List<Exception> exs = new List<Exception>();
                    exs.Add(new Exception("No data from MailChimp"));
                return exs;
            }

           public string[] GetListSegments()
            {
                string strMailChimpURL = ConfigurationManager.AppSettings.Get(0);
                string strMailChimpAPIKey = ConfigurationManager.AppSettings.Get(1);
                string strMailChimpListID = ConfigurationManager.AppSettings.Get(2);
                string strMethod = "listInterestGroupings";
                MailChimpAPIRequest myPost = new MailChimpAPIRequest(strMailChimpURL, strMethod);
                myPost.Add("output", "xml");
                myPost.Add("apikey", strMailChimpAPIKey);
                myPost.Add("id", strMailChimpListID);
                string strMailChimpResponse = myPost.GetResponse();
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(strMailChimpResponse);
                XmlNodeList nodes = doc.SelectNodes("//groups/struct");
                string strTest = "";
                foreach (XmlNode node in nodes)
                {
                    strTest = strTest + node["name"].InnerText + "|";
                }

                string[] selectedValues = strTest.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                return selectedValues;
            }
        }

    When I select it from the Type dropdown, the Preview works fine.

    But when I click on SAVE, it says there is a problem with the Settings?

     

    Any help much appreciated.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Oct 26, 2011 @ 22:28
    Jan Skovgaard
    0

    Hi Peter

    Could you perhaps post the message you're getting when you're trying to save the selected value? :)

    /Jan

  • Peter Drayton 29 posts 49 karma points
    Dec 09, 2011 @ 12:19
    Peter Drayton
    0

    Managed to fix it.

     

    Many thanks,

     

     

    Peter.

  • Shaun 248 posts 475 karma points
    Aug 01, 2012 @ 15:50
    Shaun
    0

    Out of interest, can you remember the cause of the problem? I'm seeing the same thing with one I've created. any prevalue created using the default options stores correctly tho.

     

  • AnandBhopale 54 posts 172 karma points
    Apr 20, 2021 @ 08:02
    AnandBhopale
    0

    What was the fix ? I am facing same problem.

Please Sign in or register to post replies

Write your reply to:

Draft