Copied to clipboard

Flag this post as spam?

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


  • Anders Burla 2560 posts 8256 karma points
    Jun 27, 2013 @ 08:49
    Anders Burla
    0

    AbstractDataEditor OnSave in Umbraco 6.1

    Hi everyone

    The core was optimized for some speeding in Umbraco 6.1 which means when saving a node in the Umbraco admin UI - the save process is more speedy. BUT, my problem with this performance update is when I have a custom data type which needs to be dependend on data entered in another field. Before 6.1 I could use new Document( nodeId ) in my OnSave method of my AbstractDataEditor. This would give me access to the data that was saved in the DB for fields that had been saved before my custom property. But in 6.1 all properties will be saved in the DB in one sql call - so now when I load the Document during the OnSave method - I dont have access to the data from the other fields.

    Do anyone know how I can get the data from the other fields in my OnSave method so I can make my custom data type use a value entered in another of the properties for the Umbraco node.

    Example:
    I have a doc type named news with two properties. Heading and Sub heading. Lets say my Sub heading is using a custom data type I build. When I save the node I want my Sub heading data type to use data from the Heading property. In 6.1- this worked by using new Document(nodeId).getProperty("Heading") - would give the value that was entered because each property was saved to DB in its own DB call. In 6.1+ when I use the getProperty in the OnSave method - the value is empty because the "Heading" property hasen't been saved to the DB yet.

    Kind regards
    Anders

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jun 27, 2013 @ 09:46
    Jeroen Breuer
    100

    Hello,

    I don't think this is new in 6.1, but 6.0 actually. Since 6.0 it's using transactions which means values from other properties aren't available yet. Instead of using the the OnSave event on your AbstractDataEditor you could try to use the document beforesave and aftersave events. In beforesave the values aren't available, but in the aftersave they are. They only way I was able to solve it was by getting the value in the aftersave event and than save again. That's what I did for DAMP.

    More info here: http://issues.umbraco.org/issue/U4-1372

    In the V6 API you can call .Save again in the AfterSave event with .Save(false) so the events aren't fired again which could cause an infinite loop: http://issues.umbraco.org/issue/U4-1564

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jun 27, 2013 @ 09:53
    Jeroen Breuer
    0

    If http://issues.umbraco.org/issue/U4-1372 is too long to read the values are availble in the before save event, but only like this:

    sender.getProperty("propAlias")

    This won't work because you get the object again and the values aren't saved yet:

    Document(id).getProperty("propAlias")

    See this comment: http://issues.umbraco.org/issue/U4-1372#comment=67-4430

    Jeroen

  • Anders Burla 2560 posts 8256 karma points
    Jun 27, 2013 @ 12:30
    Anders Burla
    0

    Hi Jeroen

    THANKS for this great info. Makes sense - I will try and use my new knowledge :)

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft