How to create a custom table using the API

Lance Keay asked on October 31, 2018 21:08

Is there an easy way to create a custom table using the API? I can find a CustomTableItemProvider, but I don't see a CustomTableInfoProvider...

Recent Answers


Peter Mogilnitski answered on October 31, 2018 21:28 (last edited on October 31, 2018 21:31)

I would guess there is. You need to use DataClassInfoProvider class. But it might be not pretty straight forward. I'd say it should be similar to online forms. Here is an example how to create a field using api. The same should apply to a custom table.

0 votesVote for this answer Mark as a Correct answer

Lance Keay answered on October 31, 2018 21:35

@peter - that example shows how to add a field to an existing form.

The only place I can find table creation is in the NewClassWizard admin control.. but it's pretty hairy in there. I've tried to extract and reuse some of the code, but it seems like an awful lot of code for a small table with just a few columns.

0 votesVote for this answer Mark as a Correct answer

Lance Keay answered on October 31, 2018 21:49

The docs suspiciously leave out how to create a table: https://docs.kentico.com/api11/content-management/custom-table-data - the other api examples usually show how to create the object and then CRUD it.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 31, 2018 22:02

Adding field to a form or a custom table is the same. It is the same principle.

Sure you can take a look at what happens inside CMS\CMSModules\CustomTables*.* and use reshaper to get to the bottom of it. Kinda crazy though.

The other way is create export package with test custom table. Look inside export package zip. There is an xml file with table schema , that describes your table. You need to generate such xml file. And use import api to create your table. Also not a very straight forward way.

Essentially in both cases it comes down to working with class xml schema.

P.S. You can always ask the support if they have such a script.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.