I have a simple Kentico UI page which appears as a tab within the Pages module. At the moment it just contains a button which, when clicked, updates a property of the current TreeNode and saves it. This is an extract from the code:
protected void doSomething_Click(object sender, EventArgs e)
{
if (Node != null)
{
Node.SetValue("MyBooleanField", true);
Node.Update(true);
Whenever this button is clicked I'm finding the relevant property is updated, but the NodeAlias and NodeAliasPath properties in CMS_Tree are set to an empty string and "/" respectively. This causes all sorts of problems because these properties now match the Root node.
I've tried replacing Node.Update(true)
with Node.Update()
and DocumentHelper.UpdateDocument(Node)
but always the same result.
What am I doing wrong? I'm literally not doing anything else so why would Kentico change the node alias?
Update
Something I omitted from the above code extract is that the TreeNode object I'm updating is actually pulled from the database using the following code. It seems that this is where the problem lies so apologies for omitting. It appears that because I'm specifying columns here then it's only those columns which are updated, with others getting emptied. If I don't specify columns in the DocumentHelper statement then the problem goes away. Would be great if someone could explain this. I assumed that specifying columns simply had the effect of eager loading those values but clearly the impact is greater than that.
var node = DocumentHelper.GetDocuments()
.Culture(cultureCode)
.CombineWithDefaultCulture(true)
.OnSite(new CMS.DataEngine.SiteInfoIdentifier(siteName))
.Columns(columns)
.Published(publishedOnly)
.WhereEquals("NodeID", nodeId)
.SingleOrDefault();