Wrong NodeName in DocumentQuery after Document rename.

James Mosquito asked on June 30, 2020 15:54

Hi,

I have a DocumentType with a field linked to the Document's NodeName property. I can add and rename a page and all appears fine. But when I use the DocumentHelper to select a group of nodes I noticed that the original NodeName is returned for pages that have been renamed.

The database field appears to have been updated correctly. And the NodeName in the content tree of the Pages dashboard shows the correct value.

I thought it could be a cache problem, but I also updated the PageAlias of the same nodes and that change does show up in the query so I'm confused where the DocumentHelper is getting the NodeName value from?

Thanks, J

Correct Answer

Dmitry Bastron answered on July 2, 2020 17:29

James, the field you are amending on the screenshot is actually a DocumentName (not NodeName). NodeName is not editable by default unless you configure it inside of PageType. Kentico does not update NodeName automatically, only create it when the node is created at first. Please have a look at Page Database structure, it should explain the difference between Node and Document and how they tie together.

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on July 1, 2020 18:12

Usually you are not getting the latest published version... How does your query look like? Is it by type, path a specific ID (node/doc/...) or another specific property?

Check if you have the correct document version. Correct culture or adding PublishedVersion().

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on July 1, 2020 18:34

Hi James,

It's not very clear what do you mean by "DocumentHelper to select a group of nodes". Could you please post some code that causes issues? That will make it easier to help you. Also, are you using NodeName or DocumentName? Does your website has multiple cultures? NodeName is taken from the first culture version created typically.

0 votesVote for this answer Mark as a Correct answer

James Mosquito answered on July 2, 2020 07:44 (last edited on July 2, 2020 07:52)

Hi David, thank you for the suggestion. The query I am using looks like this:

var childNodes = DocumentHelper.GetDocuments()
            .Path(path, PathTypeEnum.Children)
            .LatestVersion()
            .Published()
            .OnSite(SiteContext.CurrentSiteName)
            .Culture(_cultureName)
            .CombineWithDefaultCulture()
            .OrderByAscending("NodeOrder")
            .Where(x => x.Parent.NodeAliasPath.Equals(path))
            .ToList();

I have tried using PublishedVersion() too.

The result is always the same when debugging through the IDE. Any node where I have changed the field linked to the page name returns the NodeName that was assigned when the page was created. Equally changes I make to the page alias are returned correctly in the NodeAlias, NodeAliasPath etc. suggesting I have the latest version.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on July 2, 2020 09:56

James, selection code appears to be all fine. Could you also post the code that changes the NodeName? When is it run: scheduled task, global event handler, external application?

0 votesVote for this answer Mark as a Correct answer

James Mosquito answered on July 2, 2020 15:46 (last edited on July 2, 2020 16:00)

Hi Dmitry, the name change is being made in the Pages dashboard of the CMS via the node's Content tab.

In the attached image you can see that I have changed the Name property to Service-6 and that the highlighted node in the content tree has been updated with this name. However, the MVC function (from my last post) returns Service-3 as the NodeName. If I change the name again, and then again the function always returns Service-3 (the name given to the node when it was first created).

I have put a breakpoint inside the function to make sure that it is always being hit and that the result is not coming from cache.

Thanks, J

Edit: The image attachment option doesn't appear to be working so this is the direct link to the hosted image if you need to see it: https://ibb.co/x1SgN08

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on July 2, 2020 16:13

So although tied together can you retrieve that specific Name field instead of the NodeName... If you do get the correct value the Node is probably not updated when changing that field.

0 votesVote for this answer Mark as a Correct answer

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