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.
Here's a screenshot of the XPath query that is unable to find the node.
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!
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.
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.
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. ..
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.
Here's a screenshot of the XPath query that is unable to find the node.
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!
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
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:
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
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?:
is working on a reply...