Copied to clipboard

Flag this post as spam?

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


  • anthony hall 222 posts 536 karma points
    Aug 05, 2009 @ 17:50
    anthony hall
    1

    Action on node creation

    I'm hoping to programitcally set a default value of a property. This value will be depend on some business logic and will be different for every node. Is it possible to amend the node properties just after create. I've notice the following handler is hit just after create. But i don't believe the node has been created at this point

      umbraco.interfaces.IAction[] umbraco.BusinessLogic.Actions.IActionHandler.ReturnActions()  {

                 // i want add my business logic here but it seems the node hasn't been created yet. 

    return new umbraco.interfaces.IAction[] { new umbraco.BusinessLogic.Actions.ActionPublish() };

            }

     

    I am aware that i can amend the node on 'umbraco.BusinessLogic.Actions.IActionHandler.Execute'  but this is hit on save. 

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Aug 05, 2009 @ 18:45
    Morten Bock
    101

    Are you using V4? If so, then you should use the new events instead. Take a look at this article for a sample:

    http://umbraco.org/documentation/books/api-cheatsheet/using-applicationbase-to-register-events

    You could do something like this (written directly here, so may have syntax errors):

    public class AppBase : umbraco.BusinessLogic.ApplicationBase {

    public AppBase() {
    Document.New += new Document.NewEventHandler(Document_New);
    }
    void Document_New(Document sender, PublishEventArgs e) {
    //Do your businesslogic here
    string yourvalue = "blahblah";

    //This will set and save the value to the document
    sender.GetProperty("yourproperty").value = yourvalue;

    }
    }

    This fires when you create the document. So that is before you save/publish or enter anything into the doc.

    Principle is the same if you want to do it every time the document is saved/published. See a list of all events here:

    http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events

  • anthony hall 222 posts 536 karma points
    Aug 05, 2009 @ 18:52
    anthony hall
    0

    perfect,  sorry i wanted to give you thumbs up and the correct answer credit. Seems you can only do one. 

  • anthony hall 222 posts 536 karma points
    Aug 05, 2009 @ 18:53
    anthony hall
    0

    oh, i think it works if you refresh :)

Please Sign in or register to post replies

Write your reply to:

Draft