Developer Forum »
Delete childnodes, including deactivated children
62 posts

When I run this code in my workflow, it deletes all the nodes except deactivated nodes. They should be deleted as well, and I try to include them in "GetAllChildren(4,true,true)".

Is there a better way of doing this?

 

            foreach (HierarchicalContent hc in currentMother.GetAllChildren(4, true, true))

            {

                childrenToBeDeleted.Add(hc.NodeId);

            }

WFContext.Engine.SystemSession.DeleteNode(Aql.In(AqlContent.NodeId, childrenToBeDeleted), true);
WFContext.Engine.SystemSession.DeleteNode(currentMother.NodeId, true); 

181 posts

Hi!

This was originally by design that the DeleteNode method that takes a where expression to not delete deactivated nodes, since you can't specify if you want to delete deactivated nodes or not in the where expression.

This is linked to the fact that by default queries only return published nodes and not deactivated nodes.

After having reviewed it now, we're changing the behaviour to delete deactivated nodes when part of the resulting where expression. This will be part of the next build of Webnodes. In the meantime, you can change this line:

WFContext.Engine.SystemSession.DeleteNode(Aql.In(AqlContent.NodeId, childrenToBeDeleted), true);

To:

 foreach (int childId in childrenToBeDeleted) {
            WFContext.Engine.SystemSession.DeleteNode(childId, false);
        }
62 posts

Ok, thanks. No problem to use this code instead.

1