I would suggest you do it on ContentService.Saved, since you will have access to the parent, but you aren't relying on the content being published.
If you need it to be published together with the parent, i would attach a new handler to ContentService.Published or ContentService.Publishing depending on you needing it to happend after or while publishing.
I think you should be able to, but haven't tested it. The "saved" event should be rasied after the content has been saved, and the id has been created and set.
Umbraco Events - Creating Child nodes automatically when a new Node is created.
Hi guys,
When a user adds a node of a given document type to the content tree, I want to be able to create new child nodes below the new node automatically.
I know the best way to do this is using umbraco events, but I am not 100% sure which is the best event to use.
Has any one got an example of how best to do this in umbraco 8.
Hi,
I would suggest you do it on
ContentService.Saved
, since you will have access to the parent, but you aren't relying on the content being published.If you need it to be published together with the parent, i would attach a new handler to
ContentService.Published
orContentService.Publishing
depending on you needing it to happend after or while publishing.HTH :)
But I'm pretty sure on saved... you don't have access to the id of that newly saved node.
https://our.umbraco.com/forum/using-umbraco-and-getting-started/100726-umbraco-events-getting-newly-created-node-inside-the-contentservicesaved-event
I have actually done this before, but I was trying to find out if there was a standard way to do it - maybe someone had someone had an example.
I think creating a node automatically is probably a popular requirement, would be nice to see some offical docs on a full example.
I think you should be able to, but haven't tested it. The "saved" event should be rasied after the content has been saved, and the id has been created and set.
This is what has been done on the example found in this issue: https://github.com/umbraco/Umbraco-CMS/issues/6291
If you're willing to use a package, this makes it easy: https://our.umbraco.com/packages/backoffice-extensions/autonode/
is working on a reply...