Copied to clipboard

Flag this post as spam?

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


  • Tom 161 posts 322 karma points
    Feb 17, 2017 @ 15:27
    Tom
    0

    How to Update publishedAt field programmatically

    In 7.2.4, content editors were able to update the "Publish At" and "UnPublish At" fields WITHOUT having "publish" role. In 7.5.9 content editors must have the "publish" role in order to update these two fields.

    In my implementation of Umbraco, our Editors are not allowed to have the publish role.

    So is there a way to update the "publishedAt" and "unPublishedAt" fields.

    I have a content service GetById object, but when I inspect the properties, I don't see the "publishedAt" and "unPublishedAt" fields. I am using C# Visual Studio 2015, with MVC4 and Umbraco 7.5.9.

    Thanks

    Tom

  • Tom 161 posts 322 karma points
    Feb 17, 2017 @ 19:59
    Tom
    100

    I answered my own question by creating a new tab in one of my document types which has two Date/Time fields on them. Then on save or send to publish, I use the values from these 2 fields to update Umbraco's ContentService.Saving += ContentService_Saving;

        private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
        {
            int id = 0;
            foreach (var y in e.SavedEntities)
            {
                if (y.Properties["publishAt"].Value == null)
                    y.ReleaseDate = null;
                else
                    y.ReleaseDate = Convert.ToDateTime(y.Properties["publishAt"].Value.ToString());
                if (y.Properties["UnpublishAt"].Value == null)
                    y.ExpireDate = null;
                else
                y.ExpireDate = Convert.ToDateTime(y.Properties["UnpublishAt"].Value.ToString());
            }
        }
    
  • 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