Custom Transformation Code Find If Children Exist With A Boolean Property Set

Tom F asked on January 4, 2017 07:39

Hi I'm trying to look at either writing a transformation method in the CMSTransformation class or get some help working out how I might check if any children of the current node exist where the child has a boolean property of a given name and that property is set to true.

In the text/xml transformation currently I have: Documents.Where("NodeID = " + NodeID).FirstItem.Children.Count > 0

If I convert the type to an ascx I'm thinking I'll need to do something linqy like

Documents.Where(n => n.NodeID == NodeID).FirstItem.Children.Where(c=> c.GetBooleanValue("mybool")).Count > 0

I was thinking if I should do something like pass the current NodeID in to a method in the CMSTransformation class and have a method with a boolean return type and go from there..

Just wondering if there were any other suggestions?

Recent Answers


Roman Hutnyk answered on January 4, 2017 10:23

I'd recommend to implement some custom query and use hierarchical viewer to present data.

This will have better performance as it calls database once vs. 1 + number of items in list (to get children).

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 4, 2017 14:36

I've done what you have suggested Tom several times and it works in a pinch but the ultimate solution would be what Roman suggests because if you're loading that navigation or webpart each time a page loads you're creating quite a few queries against your database. The way I was able to get away with it is I specifically cached that webpart for x hours because it was navigation and it didn't change but maybe once or twice per month. So unless you can put some limits on those database calls or add some aggressive caching, I'd implement what Roman suggests.

0 votesVote for this answer Mark as a Correct answer

Tom F answered on January 4, 2017 23:23

Thanks to you both for your replies most appreciated.

I'll look in to working out how to implement a custom query and let you know how I go.

This is already in the context of a hierarchical viewer it's one of the transformations to see if it has children and apply a dropdown class.

I'll look in to custom queries now. thank you :)

0 votesVote for this answer Mark as a Correct answer

Tom F answered on January 4, 2017 23:42

The query side of things was super straightforward but I was wondering how I use it in the context of an aspx template and DocumentHierarchicalViewer?

Thanks again

0 votesVote for this answer Mark as a Correct answer

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