Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Assign custom fields to Subscriber object View modes: 
User avatar
Member
Member
robert-tailor.co - 6/13/2012 11:53:54 PM
   
Assign custom fields to Subscriber object
Hi,

I have just upgraded a client site from v4.1 to v6. The client site allows people to subscribe to their newsletters using a custom form submission. In Kentico v4.1 they were able to set custom fields to the 'Subscriber' class object using:

sb.DataClass.SetValue(<field name>,<value>);

e.g. sb.DataClass.SetValue("SubscriberTitle", ddlTitle.SelectedItem.Text);

This is no longer possible in v6. The same (previosuly working) line of code now returns a compilation error:

CMS.DataEngine.AbstractInfo<CMS.Newsletter.Subscriber>.DataClass is inaccessible due to it's protection level.

So how do I assign custom fields to Subscriber objects in Kentico v6?

The previous working section of code is as follows:


// Get subscriber info
Subscriber sb = SubscriberProvider.GetSubscriberByEmail(txtEmail.Text,CMSContext.CurrentSiteID);

if (sb == null)
{
// Create subscriber
if (sb == null)
{
sb = new Subscriber();
}

// E-mail
sb.SubscriberEmail = txtEmail.Text.Trim();
sb.SubscriberFirstName = txtFirstName.Text;
sb.SubscriberLastName = txtLastName.Text;

// Full name
sb.SubscriberFullName = sb.SubscriberFirstName + " " + sb.SubscriberLastName;

//TODO assign custom fields here
//sb.DataClass.SetValue(<field name>,<value>);
sb.DataClass.SetValue("SubscriberTitle", ddlTitle.SelectedItem.Text);
sb.DataClass.SetValue("SubscriberState",ddlState.SelectedItem.Text);
sb.DataClass.SetValue("SubscriberNewsletterType", ddlType.SelectedItem.Text);

// Create guid
sb.SubscriberGUID = Guid.NewGuid();

// Site
sb.SubscriberSiteID = CMSContext.CurrentSite.SiteID;

// Save subscriber info
SubscriberProvider.SetSubscriber(sb);
}

// Return subscriber info object
return sb;

User avatar
Member
Member
kentico_michal - 6/14/2012 6:39:26 AM
   
RE:Assign custom fields to Subscriber object
Hi,

You can set custom properties as shown here:

subscriberObj.SetValue("<column name>", value);

Best regards,
Michal Legen

User avatar
Member
Member
robert-tailor.co - 6/14/2012 4:34:34 PM
   
RE:Assign custom fields to Subscriber object
kentico_michal wrote: Hi,

You can set custom properties as shown here:

subscriberObj.SetValue("<column name>", value);

Best regards,
Michal Legen

Thank you.

Where would I have found this information online? There appears to be no mention of it in the Developer's Guide.

Is there documentation that shows all the API changes between different versions of Kentico?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 6/14/2012 5:44:14 PM
   
RE:Assign custom fields to Subscriber object
Hi,

There were several big changes in the API. Please see this blog post for more details.

Best regards,
Juraj Ondrus

User avatar
Member
Member
robert-tailor.co - 6/14/2012 6:46:03 PM
   
RE:Assign custom fields to Subscriber object
kentico_jurajo wrote: Hi,

There were several big changes in the API. Please see this blog post for more details.

Best regards,
Juraj Ondrus

Great. Thanks for your help!