I have a question about adding with custom Fields using ASP.NET 2.0
Basically what i am trying to do is subscribe users with some custom fields attached. I can do this for plain text things e.g sex, age, shoe size etc using AddSubscriberWithCustomFields.
I can not figure out however how I add a multoptions custom field .
E.g. Custom field called FavDrink
FavDrink (edit) [FavDrink,fallback=] Multi-Options (select many)
How do I parse these options and add them to the array of SubscriberCustomField?
Thanks in advance, Gareth.
You shouldn't need to parse it, you can just pass it in as a comma delimited string like it would be if you weren't using the API. Check out the post values if you use the default HTML form you can generate within CM. Then just make the values mimic that format in your API calls.
It's great to see some discussion starting to go on in this section of the forum.
As aognenoff suggests, if you've used the same field name for all of your check boxes on your sign up form, the post back will contain the values for these check boxes as comma separated values.
However the next part is not so straight forward. You DO need to break them up in order to make the SOAP API call from .NET, and assign the values to multiple SubscriberCustomField objects, and pass the array of these in through the call.
The trick is to just have multiple instances of these objects, but with the same Key, added to the array to pass in. Given the situation of your Values being a comma separated string, here's one way to do this.
In .NET, there is a String.Split() method, which takes a character argument to split on, you would provide ',' as this parameter.
So you can apply this to your posted value, and it will result in a string array containing each of the checked values. Then, you can simply iterate through this array, creating a new SubscriberCustomField object, assigning the same Key to each, but with the different values. Add it to the SubscriberCutomField array you intend to pass to the call, and you're done.
Hmmm...good to know. So can you access the individual selections to create segments and personalize messages based on each value or is it treated as a single string once it makes it into CM?
That's partially correct aognenoff.
Segmentation, yes, you can do this on the individual values no worries. The values are stored sepearately once entered.
Personalization, however, we only present one of the selected mutli-option values, due to not being able to insert all of them in a way that would/could be expected.
Would that be the first value selected or how is that chosen?
That'd be the first selected option upon the actual sending of the campaign.
Its been a while owing to the time differences and a busy week etc. That worked, what I essentially ended up with was bunch of If's which added the SubscriberCustomField if required. Not terribly elegant but functional nonetheless.
Many thanks for you input.
List<SubscriberCustomField> lstCollectedCustomFields = new List<SubscriberCustomField>();
if (strFdGin == "True")
SubscriberCustomField scfFdGin = new SubscriberCustomField();
scfFdGin.Key = "[FavDrink]";
scfFdGin.Value = "26175";
if (strFdVodka == "True")
SubscriberCustomField scfFdVodka = new SubscriberCustomField();
scfFdVodka.Key = "[FavDrink]";
scfFdVodka.Value = "26176";
if (strFdBeer == "True")
SubscriberCustomField scfFBeer = new SubscriberCustomField();
scfFBeer.Key = "[FavDrink]";
scfFBeer.Value = "26177";
From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that drive real business results.Get started for free