Copied to clipboard

Flag this post as spam?

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


  • greengiant83 88 posts 109 karma points
    Feb 18, 2011 @ 16:41
    greengiant83
    0

    Create child documents when a document is created

    Is there a way to way to have umbraco create a series of child documents when a document of a certain document type is created automatically?

    I have a fundraiser document type and registration document type as well as a handful of others.  When a new fundraiser is created I need to have a register page and some others created under it.  Is there a way for these child pages to created automaticaly whenever a new fundraiser document is created?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 18, 2011 @ 16:48
    Tom Fulton
    0

    Hi,

    You could do this with the API by using ApplicationBase Events, something like:

            void Document_AfterNew(object sender, umbraco.cms.businesslogic.NewEventArgs e)
    {
    Document doc = new Document(true,((CMSNode)sender).Id);
    if (doc.ContentType.Alias == "Fundraiser")
    {
    Document.MakeNew("Name of new node", DocumentType.GetByAlias("RegisterPage"), umbraco.BusinessLogic.User.GetCurrent(), doc.Id);
    }
    }

    See wiki: Using ApplicaitonBase to register events

    Richard Soeteman also had a good blog post about events

    -Tom

  • greengiant83 88 posts 109 karma points
    Feb 18, 2011 @ 17:03
    greengiant83
    0

    Awesome!  Thanks for the answer, Tom.  This CMS rocks!  What a beautiful api.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 18, 2011 @ 17:07
    Tom Fulton
    0

    Not a problem!  Also I forgot to mention this will only create the document, not publish anything

    If you want to set properties and/or Publish:

    Document newDoc = Document.MakeNew("Name of new node", DocumentType.GetByAlias("RegisterPage"), umbraco.BusinessLogic.User.GetCurrent(), doc.Id);
    newDoc.getProperty("propertyAlias").Value = "value";
    newDoc.Save();
    newDoc.Publish(umbraco.BusinessLogic.User.GetCurrent());
    umbraco.library.UpdateDocumentCache(newDoc.Id);

    -Tom

  • Matt Taylor 873 posts 2086 karma points
    Nov 30, 2011 @ 14:47
    Matt Taylor
    0

    Great, this is just what I was looking for.

    Thanks.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies