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 370 posts 926 karma points
    Jul 07, 2015 @ 20:22
    Ayo Adesina
    0

    Perform Action When property changes - Umbraco Events

    When a user saves a given doc type I want to check a proprty value, if it has changed from the original value I want to perform some action.

    Any Ideas?

    Thanks in advance.

  • Ayo Adesina 370 posts 926 karma points
    Jul 09, 2015 @ 10:32
    Ayo Adesina
    0

    Someone must know how to do this?

  • Chriztian Steinmeier 2698 posts 8107 karma points MVP 3x admin c-trib
    Jul 09, 2015 @ 10:36
    Chriztian Steinmeier
    0

    Hi Ayo,

    I guess you can use an event for this - if you have access to Umbraco.TV, there's a series of videos explaining how to do something like that:

    Umbraco.TV Developer/Events

    Hope that helps,

    /Chriztian

  • Ayo Adesina 370 posts 926 karma points
    Jul 10, 2015 @ 23:10
    Ayo Adesina
    0

    Hi Chriztian....

    I know how to use the events, what I need help with is the santax... heres what I mean.

        void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e)
        {
            foreach (var myNode in e.SavedEntities.Where(x => x.HasProperty("propertyName")))
            { 
                //if (myNode.GetPropertyValue("propertyName").hasChanged)
        // then
        //bla bla bla
    
            }
        }
    

    Also is there a version of this method that is a single IContent object rather than a list, In previous versions was this not the case?

    Thanks

  • Ayo Adesina 370 posts 926 karma points
    Jul 10, 2015 @ 23:20
    Ayo Adesina
    0

    I found this method

    IContent.IsPropertyDirty() can't find any documentation on it though... any ideas?

  • Ayo Adesina 370 posts 926 karma points
    Jul 12, 2015 @ 11:45
    Ayo Adesina
    2

    This is the answer I was looking for..................... why is there no documentation on this method :-/

    foreach (var myNode in e.SavedEntities.Where(x => x.HasProperty("myproperty")))
                {
                    if (myNode.IsPropertyDirty("packageStatus"))
                    {
                               //perform action
                    }
                }
    
  • Michaela Ivanova 12 posts 103 karma points
    Feb 06, 2019 @ 11:25
    Michaela Ivanova
    0

    I found out that in the ContentService_Publishing you can compare current value and old one for example:

     private void ContentService_Publishing(PublishEventArgs<IContent> args, ApplicationContext applicationContext)
        {
            var contentService = applicationContext.Services.ContentService;
    
            foreach (var item in args.PublishedEntities)
            {
                var name = item.Name;
                var id = item.Id;
                var oldName = contentService.GetById(id).Name;
    
                if (name != oldName)
                {
                    //do something
                }
    
            }
    
        }
    

    And register your method here:

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ContentService.Publishing += (sender, arg) => ContentService_Publishing(arg, applicationContext);
    
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft