Calling Update on TreeNode is clearing NodeAliasPath

Tom Troughton asked on March 30, 2016 20:54

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();

Correct Answer

Tom Troughton answered on March 31, 2016 10:10

Thanks Brenden. The answer is no. However, I've now discovered the cause. Please see the update to my original question. However, I'd be interested in an explanation if you have one.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on March 30, 2016 23:28

Are you updating the field which is responsible for creating the node alias or document name?

1 votesVote for this answer Mark as a Correct answer

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