Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jon Davis 16 posts 109 karma points
    Jul 03, 2020 @ 21:23
    Jon Davis
    0

    UmbracoHelper.TypedContentAtXPath not finding node created with ContentService.SaveAndPublishWithStatus

    v7.12.3

    I'm having an issue when creating a node via the ContentService's SaveAndPublishWithStatus method. The node is created and I can see it in the Back Office. I can navigate to the page and see the content. However, if I try to get the node via UmbracoHelper.TypedContentAtXPath(), it's not returned. In order for TypedContentAtXPath() to return the node, I have to go into the Back Office and manually Save and Pubish the node, then all is well.

    Here's a screenshot of the code that creates the content and calls SaveAndPublishWithStatus(). As you can see, the result of the SaveAndPublishWithStatus operation is Success. If I drill down further into the result object I see that the content is indeed Published.

    enter image description here

    Here's a screenshot of the XPath query that is unable to find the node.

    enter image description here

    Once I manually Save and Publish the node from the Back Office, the above code works as expected and XPath returns the node.

    I've tried setting the raiseEvents flag to false when calling SaveAndPublishWithStatus, but that had no effect.

    Not sure where else to look to troubleshoot this issue. Any ideas would be most appreciated!

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Jul 05, 2020 @ 09:16
    Steve Morgan
    0

    Hi,

    When are you calling the GetNextPosterPageId method - is it during this publish event?

    The content service operates directly on the database. The umbraco helper uses the cache. From memory I've had problems with events on creating / publishing nodes and then trying to use the umbraco cache to "get" the node.

    I think (though you'll need to check this) that the cache is only updated when the publish event is fully finished. So if you try to use the cache during a publish you'll find that new nodes don't exist yet. I needed to get the new nodes URL and do something with it and had this issue.

    Does this make sense in your situation?

    Steve

  • Jon Davis 16 posts 109 karma points
    Jul 05, 2020 @ 12:28
    Jon Davis
    0

    Hi Steve,

    Thanks for the reply.

    GetNextPosterPageId is not called within the context of a publish event. It's called from this Surface Controller method:

        public ActionResult GetNextPosterPage(int currentPosterPageId, int posterCategoryPageId)
        {
            var nextPosterPageId = _posterHallService.GetNextPosterPageId(currentPosterPageId, posterCategoryPageId);
    
            return RedirectToUmbracoPage(nextPosterPageId);
        }
    

    However, the method CreateOrUpdatePostersByCategory that creates the PosterPage nodes may or may not be called from within the context of an Publish event. But it doesn't seem to matter, I run into this problem either way.

    Jon

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Jul 07, 2020 @ 09:19
    Steve Morgan
    0

    OK .

    Sounds like you have found a bug there. The cache in Umbraco is now no longer in XML so perhaps the Xpath stuff is less used thab before. As you have the container id of the node do you need to use this anyhow?

    Would something instead like this not work?:

        var categoryNode = _umbracoHelper.TypedContent(currentPosterPageId);
    var posters = categoryNode.Children("posterPage").Where(x => x.GetPropertyValue<bool>("withdrawn") == false); //.Select. ..
    
Please Sign in or register to post replies

Write your reply to:

Draft