I'm programmatically creating a node, setting a sort order value to make it the first, rather than last child of its parent. Saving the node then over-writes the set order:
// ... create newNode, set some properties
// get the children of the parent, sort by sort order
// get the first (ie lowest sortOrder), subtract 1 to put the new node first
var parent = contentService.getById(id);
var sortOrder = parent.Children().OrderBy(c => c.SortOrder).First().SortOrder - 1;
// set the newNode sort order
newNode.SortOrder = sortOrder;
contentService.Save(newNode);
// newNode.SortOrder = parent.Children().OrderBy(c => c.SortOrder).Last().SortOrder + 1;
Thought that might be it, but nah - I'm refactoring a bit of code which previously looped through all the children, incremented the sortorder, saved and published each node, which was slow.
Given that has run plenty of times previously, the lowest sort order value is pretty high, so no negative.
The new node is unsaved when I set the value, might try fetching the new sort order value, saving the new node, setting the sort order and resaving. Would still be way more efficient than republishing a dozen nodes.
Sort order overwritten on save?
I'm programmatically creating a node, setting a sort order value to make it the first, rather than last child of its parent. Saving the node then over-writes the set order:
Why would this be happening?
Hi Nathan,
Maybe this sets the sort order to -1 and maybe that can't be saved :
Can you check if it's negative value ?
Dave
Thought that might be it, but nah - I'm refactoring a bit of code which previously looped through all the children, incremented the sortorder, saved and published each node, which was slow.
Given that has run plenty of times previously, the lowest sort order value is pretty high, so no negative.
The new node is unsaved when I set the value, might try fetching the new sort order value, saving the new node, setting the sort order and resaving. Would still be way more efficient than republishing a dozen nodes.
Saving the new node, setting the sort order, then saving again resolved this one.
is working on a reply...