API
Version 7.x > API > Create BizForm Programmatically View modes: 
User avatar
Guest
joe@jmawebtechnologies.com - 11/20/2012 1:52:14 PM
   
Create BizForm Programmatically
Hi,

I am trying to create a BizForm programmatically, however, my code fails to work. What am I doing wrong?
public void CreateBizFormTables()
{
string bizFormNamespace = "BizForm";
string tablename = "warehousecountry";
string className = bizFormNamespace + "." + tablename;
string defaultDateTime = DateTime.Now.ToString(CultureHelper.EnglishCulture.DateTimeFormat);
TableManager tm = new TableManager(ConnectionHelper.GetConnection().ConnectionString);
tm.DropTable(tablename);
tm.CreateTable(tablename, "warehousecountryid");
var dci = BizFormInfoProvider.CreateBizFormDataClass(className, "warehousecountry", tablename, "warehousecountryid");
tm.AddTableColumn(tablename, "FormInserted", "datetime", false, defaultDateTime);
tm.AddTableColumn(tablename, "FormUpdated", "datetime", false, defaultDateTime);
tm.AddTableColumn(tablename, "WarehouseCountry", "nvarchar", true, null);
tm.AddTableColumn(tablename, "WarehouseID", "nvarchar", true, null);
DataClassInfoProvider.SetDataClass(dci);
FormHelper.UpdateInheritedClasses(dci);
CMS.DataEngine.SqlGenerator.GenerateDefaultQueries(dci, true, true);
}

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/20/2012 3:01:30 PM
   
RE:Create BizForm Programmatically
Hello,

Could you please let me know what do you mean by "my code fails to work"? Do you get any error message? Have you checked the event log for any errors regarding your issue?

Best regards,
Boris Pocatko

User avatar
Guest
joe@jmawebtechnologies.com - 11/20/2012 3:03:03 PM
   
RE:Create BizForm Programmatically
Hi,

No error messages, however, I see no BizForm under the tools > forms area. It looks like I'm missing code to save the form.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/25/2012 7:19:02 PM
   
RE:Create BizForm Programmatically
Hello,

Could you please try to compare your code with the following one?


string classname = "classname";
CMS.SettingsProvider.DataClassInfo dci = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass(classname);
if (dci != null)
{
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(dci.ClassFormDefinition);
if (fi != null)
{
// Field definition
FormFieldInfo ffi = new FormFieldInfo();
ffi.Name = "Field Name";
ffi.DataType = FormFieldDataTypeEnum.File;
ffi.AllowEmpty = true;
ffi.System = false;
ffi.FieldType = CMS.FormEngine.FormFieldControlTypeEnum.UploadControl;
ffi.Visible = true;
ffi.Caption = "Field Caption";
ffi.Description = "Field Description";
ffi.RegularExpression = "";
ffi.Enabled = true;
ffi.FileExtensions = "bmp;gif;jpg;jpeg;png;";

fi.AddFormField(ffi);

// Create a new column directly in the database
CMS.DataEngine.TableManager.AddTableColumn(dci.ClassTableName, ffi.Name, "uniqueidentifier", true, null);


dci.ClassXmlSchema = CMS.DataEngine.TableManager.GetXmlSchema(dci.ClassTableName);
dci.ClassFormDefinition = fi.GetXmlDefinition();
// Update DataClassInfo object
DataClassInfoProvider.SetDataClass(dci);
// Generate default queries
CMS.DataEngine.SqlGenerator.GenerateDefaultQueries(dci, true, true);
}
}


Best regards,
Boris Pocatko