Copied to clipboard

Flag this post as spam?

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


  • dig_nz 11 posts 60 karma points
    Aug 11, 2014 @ 13:22
    dig_nz
    0

    Update a document type property value in the published event

    Hi there,

    Is there a way to update a property value of a published content in the event

    Umbraco.Core.Services.ContentService.Published
    

    I need to save some published data into a secondary database. I can only do it in the published event (as only then I know the publish was successful). However I do want to update the umbraco content with the id of the content saved into the secondary db.

    Thanks!

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Aug 11, 2014 @ 14:23
    Amalie Wowern
    1

    You should do something like this

        foreach (var node in e.PublishedEntities)
                    {
                        if (node.ContentType.Alias == "Your documenttype alias")
                        {
    
                        node.SetValue("alias of property", "new value");
    }
       UmbracoContext.Current.Application.Services.ContentService.SaveAndPublishWithStatus(node, 0, false);                
    }
    
  • dig_nz 11 posts 60 karma points
    Aug 11, 2014 @ 15:13
    dig_nz
    0

    Hi there,

    Thank you. I am trying to call it within the 'published' event so if I call SaveAndPublishWithStatus from within the published event I get into a loop.

    Is there a way to publish without raising this event from within?

    Thank you

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Aug 11, 2014 @ 15:19
    Amalie Wowern
    0

    Are you sure its raising a loop.

    I haven't tried it in a published event, But i'm using a MediaService.Save in a media saved event without it going to loop

  • dig_nz 11 posts 60 karma points
    Aug 11, 2014 @ 16:08
    dig_nz
    0

    Hi, it does go into a loop, but I am just checking some values to exit it. Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft