Child Node Count in Transformation

Katrina Miday asked on May 19, 2015 22:50

I have a transformation that would display the number of child pages within a folder. I was using NodeChildNodesCount to display the number of children pages. With v8.1 and up, that column was removed. I've been trying to use TreeNode.Children.Count in various ways with no luck.

I'm sure I'm missing something simple, anyone have a solution to display the number of children pages? Thanks in advance!

Correct Answer

Charles Matvchuk answered on May 20, 2015 00:55

@Katrina, I have a helper function that you can use, put it your custom functions and then you can call it in any transformations by CustomFunctions.ChildCount(nodeGuid)

public static string ChildCount(string nodeGuid)
    {
        string childCount = "0";
        if(!string.IsNullOrEmpty(nodeGuid))
        {

            Guid nodeGUID = new Guid(nodeGuid);
            if(nodeGUID != null)
            {
                int nodeId = TreePathUtils.GetNodeIdByNodeGUID(nodeGUID, SiteContext.CurrentSiteName);

                if (nodeId > 0)
                {
                   TreeProvider tp = new TreeProvider(SiteContext.CurrentUser);
                    TreeNode node = tp.SelectSingleNode(nodeId);
                    childCount = node.Children.Count().ToString();
                }

                return childCount;
            }
            return childCount;
        }
        return childCount;
    }
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on May 19, 2015 23:41

You're correct Katrina, that did change in 8.1. See the article and what to use instead.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on May 20, 2015 00:57 (last edited on May 20, 2015 00:59)

Note: You would replace "CustomFunctions" with the name of your custom functions class. Also this returns count as a string, you could have it return as an int or Convert the string to an int in the transformation. You will have to pass it the nodeGuid. Since you can call this anywhere you can get the count of child pages for any page in the system from anywhere.

Basically you will create a new transformation method for yourself.

0 votesVote for this answer Mark as a Correct answer

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