Copied to clipboard

Flag this post as spam?

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


  • Mark Roffey 31 posts 184 karma points
    Mar 09, 2020 @ 11:17
    Mark Roffey
    0

    Content service save and publish raising events and putting me in an infinite loop.

    Hi,

    I have a page in which I select another page in the site using the multi node treepicker. When I save and publish that first page, I need it to save and publish the other page withthe initial page, so creating a link.

    var linkedProduct = node.GetValue("linkedProduct").ToString();
    
    var udi = Udi.Parse(linkedProduct);
    
    var iPublishedContentToUpdate = _umbracoHelper.Content(udi);
    
    var contentToUpdate = contentService.GetById(iPublishedContentToUpdate.Id);
    
    contentToUpdate.SetValue("linkedProduct", node.GetUdi());
    
    contentService.SaveAndPublish(contentToUpdate, "*", -1, false);
    

    That's no problem, except it's raising events and then getting stuck in an infinite loop. The raiseevents = false flag appears to not do anything. I've seen other posts that do indeed say that the raised event flag is redundant, so is there another way I should be approaching this?

    Many thanks in advance.

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Mar 09, 2020 @ 12:40
    Nik
    100

    Hi Mark,

    I'd be looking to use the relationship service for a feature like this. This would mean that you can update/change the relationship without publishing both content nodes. Might be better suited to your requirements to be honest.

    Nik

  • Ebin 9 posts 78 karma points
    Mar 09, 2020 @ 12:44
    Ebin
    0

    Hi ,

    Just refer this ,

    public void SaveEmailSubcription(string email)

    {

    contentService = Services.ContentService;

    var libraryArea = Umbraco.Content(4293);

            var emailSubscriptionData = libraryArea.Descendant<EmailSubscriptionData>();
            var key = emailSubscriptionData.Id;
            var node = Services.ContentService.GetById(emailSubscriptionData.Id);
            var currentPageUdis = node.GetUdi();var content = contentService.CreateContent(email,
             currentPageUdis, EmailSubscriptionItem.ModelTypeAlias, 0);
    
            content.UpdateDate = DateTime.UtcNow;
    
            content.CreateDate = DateTime.UtcNow;
    
            content.UpdateDate = DateTime.UtcNow;
    
            content.SetValue("email", email);
    
            var result = contentService.SaveAndPublish(content);
    

    }

    Thanks

  • 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