API Questions on Kentico API.
Version 5.x > API > Adding fields to Events_Attendee table View modes: 
User avatar
Member
Member
andy.holt-staffordshire.gov - 8/15/2011 3:16:56 AM
   
Adding fields to Events_Attendee table
We're trying to add some fields to the Events_Attendee table to customise the registration form for the Events Booking facility. We cloned the web part OK and added new fields onto the web form, but we are now struggling to get the form input to update the new field in the SQL table we added.

We are assuming we need to update the XML schema for the Events_Attendee table in order for the new field to be recognised, but we're unsure how this is done, so I suppose the question is both how can we accomplish this and are there any issues that we should be considering in terms of ongoing support for the customisation etc before we proceed.

Here is the code we've tried, where AttendeeOrganisation is the new field:
// Add new attendant to the event
EventAttendeeInfoProvider.SetEventAttendeeInfo(attendeeInfo);

attendeeInfo.SetValue("AttendeeOrganisation", txtOrganisation.Text);

attendeeInfo.Update();

Cheers
Andy

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/15/2011 6:34:43 AM
   
RE:Adding fields to Events_Attendee table
Hello,

you are right, you need to upgrade the class schema as well.

Please see this sample code below which you should call for each new field to update XMLSchema and DataClass. Please note that this is just sample code, so you can set values for properties of 'ffi' object as you need:
CMS.SettingsProvider.DataClassInfo dci = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("cms.EventAttendee");
if (dci != null)
{
CMS.FormEngine.FormInfo fi = new FormInfo(dci.ClassFormDefinition);
if (fi != null)
{
// add form definition
CMS.FormEngine.FormFieldInfo ffi = new CMS.FormEngine.FormFieldInfo();
ffi.Name = "nameOfCustomField";
ffi.DataType = FormFieldDataTypeEnum.Text;
ffi.AllowEmpty = true;
ffi.PublicField = false;
ffi.System = true;
ffi.Size = 200;
ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
ffi.Visible = false;
ffi.Caption = "";
ffi.DefaultValue = "";
ffi.Description = "";
ffi.RegularExpression = "";
ffi.FileExtensions = "";

fi.AddFormField(ffi);

//
dci.ClassFormDefinition = fi.GetXmlDefinition();
dci.ClassXmlSchema = CMS.DataEngine.TableManager.GetXmlSchema("Events_Attendee");

CMS.SettingsProvider.DataClassInfoProvider.SetDataClass(dci);

// Generate queries
CMS.DataEngine.SqlGenerator.GenerateDefaultQueries(dci, true, false);
}
}

Then you can use the mentioned code to update the new fields.

Best regards,
Helena Grulichova

User avatar
Member
Member
steve.jantzen-carle - 2/8/2012 11:31:00 AM
   
RE:Adding fields to Events_Attendee table
Hi Helena,

I too have tried the code above with no luck. I am using CMS 6.

Below is the code I am using
private EventAttendeeInfo AddAttendantToEvent()
{
EventAttendeeInfo attendeeInfo = new EventAttendeeInfo();
//Update the XML schema for the custom field in the Events_Attendee table
UpdateXMLSchema();
attendeeInfo.SetValue("AttendeeCredentials", txtCredentials.Text);
// Add new attendant to the event
EventAttendeeInfoProvider.SetEventAttendeeInfo(attendeeInfo);
return attendeeInfo;
}

private void UpdateXMLSchema()
{
CMS.SettingsProvider.DataClassInfo dci = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("cms.EventAttendee");
if (dci != null){
CMS.FormEngine.FormInfo fi = new FormInfo(dci.ClassFormDefinition);
if (fi != null)
{
// add form definition
CMS.FormEngine.FormFieldInfo ffi = new CMS.FormEngine.FormFieldInfo();
ffi.Name = "AttendeeCredentials";
ffi.DataType = FormFieldDataTypeEnum.Text;
ffi.AllowEmpty = true;
ffi.PublicField = false;
ffi.System = true;
ffi.Size = 200;
ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
ffi.Visible = false;
ffi.Caption = "";
ffi.DefaultValue = "";
ffi.Description = "";
ffi.RegularExpression = "";
//ffi.FileExtensions = "";

fi.AddFormField(ffi);

dci.ClassFormDefinition = fi.GetXmlDefinition();
dci.ClassXmlSchema = CMS.DataEngine.TableManager.GetXmlSchema("Events_Attendee");

CMS.SettingsProvider.DataClassInfoProvider.SetDataClass(dci);

// Generate queries
CMS.DataEngine.SqlGenerator.GenerateDefaultQueries(dci, true, false);
}
}

}

Any help would be greatly appreciated

Many Thanks!!!!
Steven Jantzen