Copied to clipboard

Flag this post as spam?

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


  • Kevin T Reynolds 12 posts 125 karma points
    17 days ago
    Kevin T Reynolds
    0

    How can I save IContent in the publishing event?

    I have a custom content approval workflow that worked in Umbraco 7 by subscribing to the content_publishing event and changing a field on the node using the ContentService API to update approval state.

    In Umbraco 8 using the .Save method

        public void UpdateWaitingApprovalStatus(IContent contentToUpdate, string waitingApprovalPropertyAlias, string waitingApprovalValueToSet)
        {
            contentToUpdate.SetValue(waitingApprovalPropertyAlias, waitingApprovalValueToSet);
            _contentService.Save(contentToUpdate);
        }
    

    I get the following error Cannot save (un)publishing content with name: test - and state: Publishing, use the dedicated SavePublished method.

    But I can't seem to find that method anywhere, is there another way to save while PublishedState is Publishing?

    I can get around it by subscribing to the published event and using SaveAndPublish but that leaves two publish events in logs.

  • Bo Jacobsen 372 posts 1576 karma points
    17 days ago
    Bo Jacobsen
    0

    Hi Kevin.

    I dunno if it helps, but try use _contentService.Save(contentToUpdate, raiseEvents = false);

  • Kevin T Reynolds 12 posts 125 karma points
    1 week ago
    Kevin T Reynolds
    100

    I tested with the Save override that accepts an IEnumerable<IContent> and sure enough it doesn't check published state and worked exactly as I needed to. so if anyone comes accross this in the future _contentService.Save(new List<IContent>() { contentToUpdate}, raiseEvents = false); works as of Umbraco 8.6.3

  • Kevin T Reynolds 12 posts 125 karma points
    1 week ago
    Kevin T Reynolds
    0

    Thanks but unfortunately not, the save method has a check for PublishedState, interestingly enough it looks like the method for saving multiple content items doesn't have that check.

    For now I'm still listening to the published event and republishing if I need to, but I'll try on a list of content tomorrow and report back.

Please Sign in or register to post replies

Write your reply to:

Draft