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; }
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.
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.
Hi Peter
Could you perhaps post the message you're getting when you're trying to save the selected value? :)
/Jan
Managed to fix it.
Many thanks,
Peter.
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.
What was the fix ? I am facing same problem.
is working on a reply...