API Questions on Kentico API.
Version 6.x > API > Document child objects do not contain custom data? View modes: 
User avatar
Member
Member
info-wolfworks - 4/14/2012 2:31:43 AM
   
Document child objects do not contain custom data?
Hi,

In my aspx template solution I want to create a complex custom form based on information from the website. I created two document types, where on the parent only one specific custom child document type can be created.

When displaying the parent, everything works out great. However, when I want to display the children, I can see the system properties are filled with the right data (DocumentName, NodeClassName etc). When accessing the custom data (like ((CMS.TreeEngine.TreeNode)Container.DataItem)["ProgrammaID"]), it returns null.

I am running Kentico CMS 6 SP1.

How can I get the data of the child elements?

Code behind:
var documents = TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Custom.ParentDocumentType", null, "Naam", 2, true, 0);

if (!DataHelper.DataSourceIsEmpty(documents))
{
MuseumRepeater.DataSource = documents.Items;
MuseumRepeater.DataBind();
}

User control:
<asp:Repeater ID="MuseumRepeater" runat="server">
<ItemTemplate>
<%#((CMS.TreeEngine.TreeNode)Container.DataItem)["Naam"] %><br/>
<asp:Repeater runat="server" ID="ProgramRepeater" DataSource="<%# ((CMS.TreeEngine.TreeNode)Container.DataItem).Children %>">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<input type="checkbox" name="ProgramId" value="<%# ((CMS.TreeEngine.TreeNode)Container.DataItem)["ProgrammaID"] %>"/>
<%# ((CMS.TreeEngine.TreeNode)Container.DataItem)["Titel"] %>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 4/16/2012 7:32:01 AM
   
RE:Document child objects do not contain custom data?
Hi,

I have not tried your code yet, but in case you would like to select data of two document types, there should be also a class name of child document.

var documents = TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Custom.ParentDocumentType;classname.ChildType", "", "Naam", 2, true,0);

If you would like to display parent/child structure, there is an option to use hierarchical viewer control or web part. You can define a hierarchical transformation, which would contain a transformation for parent and for a child document. It would be used based on the current document type. More information about this advanced control you can find here:
Hierarchical viewer

Best regards,
Ivana Tomanickova

User avatar
Member
Member
info-wolfworks - 4/16/2012 4:00:45 PM
   
RE:Document child objects do not contain custom data?
Hi Ivana,

Thanks you for your response. Whilst reading, I was almost jubilant.. That looked promising! And it was indeed something I overlooked and haven't thought of..

Unfortunately, it doesn't work. I tried the following scenario's:

TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Programma", null, null, -1, true, 0).Items[0]["ProgrammaID"] //(correct: returns 1)
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Programma", null, null, -1, true, 0).Items[0].Parent["Naam"] //(correct: returns the name)
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Museum", null, null, -1, true, 0).Items[0]["Naam"] //(correct: returns the name)
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Museum;Wolfworks.Programma", null, null, -1, true, 0).Items[0]["Naam"] //(correct: returns the name)
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Museum;Wolfworks.Programma", null, null, -1, true, 0).Items[0].Children[0]["ProgrammaID"] //(incorrect: returns null)
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Museum;Wolfworks.Programma", null, null, -1, true, 0).Items[0].Children[0].NodeName //(correct: displays the name of the program)
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Museum;Wolfworks.Programma", null, null, -1, true, 0).Items[0].Children[0]["NodeName"] //(correct, displays the name of the program)


I would expect the child objects not to be loaded in the resultset if I do not specify them in the ClassNames parameter. They show up however, including partial data. But not the custom data..

Do you have another insightful response and give me a another "D'OH!" moment? :)

And thanks for pointing out the hierarchical control. I am however still feeling more comfortable using code in the BlankASPX solution, having full control over the code and release from Development to Test to Production. This way I can tailor everything to the controls I make including clientside business logic and not worry about how I am going to fit everything together using the available controls..

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 4/18/2012 7:51:44 AM
   
RE:Document child objects do not contain custom data?
Hi,

I am not so familiar with a default asp repeater nested controls, but there is a KB article which describes this topic:
How to display hierarchical data

The custom data are available in the dataset so this seems to be some binding issue.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
info-wolfworks - 4/18/2012 2:26:40 PM
   
RE:Document child objects do not contain custom data?
Hi Ivana,

This is not related to the fact that I am using a Repeater, but using the TreeHelper.GetDocuments API call to retrieve the data of custom document types.

And the problem is that the custom data is not returned. The child nodes are retrieved, but only the strongly typed properties are available. The indexed properties are not available:
TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "nl-NL", true, "Wolfworks.Museum;Wolfworks.Programma", null, null, -1, true, 0).Items[0].Children[0]["ProgrammaID"] //(incorrect: returns null)

I investigated this before binding, by setting a breakpoint on this method call and exploring the result.

So I am wondering if I am doing something wrong, or that I have to report it as a bug?


User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 4/19/2012 6:41:31 AM
   
RE:Document child objects do not contain custom data?
Hi,

the items comes from the first table, but data set contains 2 DataTables -> null. Here is a code example which works with DataSet (with two document types - cms.blogmonth; cms.blog post) and generates this output:


March 2011
Expanding to Europe
Remote Management
April 2012
test


- markup:


<%@ Import Namespace="System.Data" %>

<asp:Repeater id="parentRepeater" runat="server">
<itemtemplate>
<b><%# DataBinder.Eval(Container.DataItem, "BlogMonthName")%></b><br>

<asp:repeater id="childRepeater" runat="server"
datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' >
<itemtemplate>
<input type="checkbox" name="ProgramId" value="<%# DataBinder.Eval(Container.DataItem, "[\"BlogPostID\"]")%>"/>
<%# DataBinder.Eval(Container.DataItem, "[\"BlogPostTitle\"]")%> </br>
</itemtemplate>
</asp:repeater>
</itemtemplate>
</asp:Repeater>


- code behind:


protected void Page_Load(object sender, EventArgs e)
{
DataSet documents = TreeHelper.GetDocuments(CMSContext.CurrentSiteName, "/%", "en-US", true, "cms.blogmonth;CMS.BlogPost", null, null, -1, false, 0);

if (!DataHelper.DataSourceIsEmpty(documents))
{


//Create the relation between the Authors and Titles tables.
documents.Relations.Add("myrelation",
documents.Tables[0].Columns["NodeID"],
documents.Tables[1].Columns["NodeParentID"]);

parentRepeater.DataSource = documents.Tables[0];
Page.DataBind();
}


In your case you need to change class names and name of fields in the markup to get required result. I hope it helps.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
info-wolfworks - 4/19/2012 6:52:46 AM
   
RE:Document child objects do not contain custom data?
Marvelous! Thank you very much, that looks indeed promising..
I will check it out. Sounds logical to add a relation to the tables, in hindsight.