Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    Jan 20, 2021 @ 16:39
    Ayo Adesina
    0

    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.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jan 20, 2021 @ 17:27
    Søren Gregersen
    0

    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 or ContentService.Publishing depending on you needing it to happend after or while publishing.

    HTH :)

  • Ayo Adesina 445 posts 1059 karma points
    Jan 20, 2021 @ 18:24
    Ayo Adesina
    0

    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.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jan 20, 2021 @ 18:36
    Søren Gregersen
    0

    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

  • Amir Khan 1287 posts 2744 karma points
    Jan 20, 2021 @ 21:03
    Amir Khan
    0

    If you're willing to use a package, this makes it easy: https://our.umbraco.com/packages/backoffice-extensions/autonode/

Please Sign in or register to post replies

Write your reply to:

Draft