I'm trying to automatically create and publish a child node when a particular parentnode type is published. For example in this case the child node is of type 'comments' and the url expected is /parentnode/comments.aspx
The trouble I'm having is that the url of the child node comments is being set to #. If I then publish the comments node manually it's fixed, but this isn't ideal.
class CreateRecipeCommentsAndRatingsNode : ApplicationBase { public CreateRecipeCommentsAndRatingsNode() { Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish); }
void Document_AfterPublish(Document sender, PublishEventArgs e) { if (sender.ContentType.Alias == "Recipe") { if (!sender.HasChildren) { string recipeName = sender.Text; User currentUser = User.GetCurrent();
Log.Add(LogTypes.Custom, sender.Id, "Creating RecipeCommentsAndRatings node for " + recipeName);
Doh, lost my edits from the original post - I suspect it's because the node is being created and published in the after publish event of the parent, but it'd be nice to be able to create and publish a child node on first publish of the parent. I'm going to try and create the child node after save of the parent, but suspect as this is earler in process it may not work. Any advice appreciated,
I found a solution, by moving the publish of the child node out from the parent Document_AfterPublish, into the parent Content_AfterUpdateDocumentCache event which happens later in the execution process.
I just ran into this same issue on 4.7.1. In my case, in the after save event I was creating and publishing some child/grandchild nodes before the parent node was published just to make it easier on the user since it was data entry type stuff. So, after the user published the parent (grand parent in this case) node, the child nodes although had the publish status never showed up in the decendants.where("visible") queries.
This is what I did when creating the nodes and it didn't work:
ib.Publish(author);
umbraco.library.UpdateDocumentCache(ib.Id); // this seems to have no effect, the main parent node in this case is still not published.
The only way that these nodes would show up after their ancestor was published was to do a refreshcontent in the after publish event when the ancestor was published.
Automatically create and publish a child node
Hi
I'm trying to automatically create and publish a child node when a particular parentnode type is published. For example in this case the child node is of type 'comments' and the url expected is /parentnode/comments.aspx
The trouble I'm having is that the url of the child node comments is being set to #. If I then publish the comments node manually it's fixed, but this isn't ideal.
You have to also push it to the XML
So add this line
Rich
Hi Rich,
Tried that, no joy unfortunately.
Thanks,
Hendy
Doh, lost my edits from the original post - I suspect it's because the node is being created and published in the after publish event of the parent, but it'd be nice to be able to create and publish a child node on first publish of the parent. I'm going to try and create the child node after save of the parent, but suspect as this is earler in process it may not work. Any advice appreciated,
Thanks,
Hendy
Hi,
I found a solution, by moving the publish of the child node out from the parent Document_AfterPublish, into the parent Content_AfterUpdateDocumentCache event which happens later in the execution process.
Cheers,
Hendy
I just ran into this same issue on 4.7.1. In my case, in the after save event I was creating and publishing some child/grandchild nodes before the parent node was published just to make it easier on the user since it was data entry type stuff. So, after the user published the parent (grand parent in this case) node, the child nodes although had the publish status never showed up in the decendants.where("visible") queries.
This is what I did when creating the nodes and it didn't work:
ib.Publish(author);
umbraco.library.UpdateDocumentCache(ib.Id); // this seems to have no effect, the main parent node in this case is still not published.
The only way that these nodes would show up after their ancestor was published was to do a refreshcontent in the after publish event when the ancestor was published.
Is this a bug or by design?
is working on a reply...