API
Version 7.x > API > Custom properties display View modes: 
User avatar
Member
Member
emccall-dataspringinc - 7/16/2013 2:51:37 PM
   
Custom properties display
Is there a way to pull a set of custom properties & their associated values for a document type not known until run-time? I have many custom document types, each with a potentially different set of custom properties (which are created dynamically). I would simply like to display them in a table on a datasheet. No editing, just display.

Any help would be sincerely appreciated!

~Erin McCall

User avatar
Member
Member
kentico_sandroj - 7/16/2013 5:49:36 PM
   
RE:Custom properties display
Hi Erin,

How are you creating/assigning the custom properties? Are they additional columns for the document type or what exactly are they?

Typically you can use custom macros to retrieve any value, or built in macros if the correct one is available.

Please let us know what the purpose of this functionality is so that we can provide accurate suggestions. Any additional information you could provide would be helpful.

Regards,
Sandro

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 7/16/2013 9:22:32 PM
   
RE:Custom properties display
Erin I have over 20 custom tables in an application and I use a simple method to map the fields across and dynamically create custom table records. You could do this same type of work with a document type. The key is to have the field names the same in your source database and your target (Kentico) database. Take a look at this code. The part that gets the XML with properties from the class is ClassFormDefinition. It doesn't matter if its a custom table or a custom document type, all the "classes" are stored in the cms_class table.
        /// <summary>
/// Creates an item for a custom table and dynamically adds the columns data based on the classinfo and row column comparison
/// </summary>
/// <param name="Dci"></param>
/// <param name="Row"></param>
/// <returns></returns>
public static bool CreateCustomTableItem(DataClassInfo Dci, DataRow Row)
{
bool okInsert = false;

// Creates new Custom table item provider
CustomTableItemProvider customTableProvider = new CustomTableItemProvider(ui);

if (Dci == null)
{
throw new Exception("Data class info cannot be null.");
}
else
{
// Creates new custom table item object
CustomTableItem newCustomTableItem = CustomTableItem.New(Dci.ClassName, customTableProvider);

List<string> classProperties = new List<string>();
// get the class definition
var doc = XDocument.Parse(Dci.ClassFormDefinition);
// get a list of all the tables properties by column value
List<string> elements = doc.Descendants("field").Select(el => el.Attribute("column").Value).ToList();

// got the class properties now compare
foreach (string str in elements)
{
// see if the class info contains the column in the data row passed in this method
if (Row.Table.Columns.Contains(str))
{
// contains the column so set a value
newCustomTableItem.SetValue(s, Row[str]);
okInsert = true;
}
}

if (okInsert)
{
// Inserts the custom table item into database
newCustomTableItem.Insert();
}
}
return okInsert;
}
If you don't use this code, no big deal, but definately check out the cms_class.ClassFormDefinition table and field to get your field definitions.