Copied to clipboard

Flag this post as spam?

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


  • progproger 52 posts 130 karma points
    Oct 05, 2015 @ 12:57
    progproger
    0

    Refresh Page On Save And Publish

    Hi,

    I've created doc type with property e.g. (Name = "ItemId" Type = "Label") When i try to "Save and Publish" node with current doc type i set some value to this label. (note that i override SendAsync method)

    currentContent.SetValue("ItemIdAlias","guidvalue");

    It sets value correctly, but label still appears to be empty. So if i click on "Save and Publish" second time it sends an empty value still... I need somehow to refresh page because on second time i need "guidvalue" to update other items

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Oct 05, 2015 @ 13:47
    Robert Foster
    0

    Hi, Can you post some code to explain how you're setting the value?

  • progproger 52 posts 130 karma points
    Oct 05, 2015 @ 14:18
    progproger
    0

    Hi Robert,

    Thanks for your response. Sure.

     protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            { 
                var path = request.RequestUri.AbsolutePath.ToLower();
                switch (path)
                {
                    case "/umbraco/backoffice/umbracoapi/content/postsave":
                    return await SaveEvent(request, cancellationToken);
                    default:
                    return await base.SendAsync(request, cancellationToken);
                }
    }
    
     private Task<HttpResponseMessage> SaveEvent(HttpRequestMessage request, CancellationToken cancellationToken)
            {
                return base.SendAsync(request, cancellationToken)
                                    .ContinueWith(task =>
                                    {
                                        var response = task.Result;
    
                                        HttpContent data = null;
                                        ContentItemDisplay content = null;
    
                                        try
                                        {
                                            data = response.Content;
                                            content = ((ObjectContent)(data)).Value as ContentItemDisplay;
    
                                            if (content.ContentTypeAlias.ToLower() == "DocTypeAlias")
                                            {
    
    
     var cs = ApplicationContext.Current.Services.ContentService;
    
     var currentEvent = cs.GetById((int)content.Id);
    currentEvent.SetValue("LabelAlias", "guidvalue");
    }
            }
    

    It sets the value for LabelAlias in DB, but page still shows an empty value and on second press "Save and Publish" i got an empty value. That's why i need to refresh the page to get "guidvalue" in label data type

  • Nick 34 posts 127 karma points
    Jan 16, 2017 @ 14:53
    Nick
    0

    Did you find a solution to this in the end?

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jan 16, 2017 @ 22:40
    Nathan Woulfe
    0

    Have you considered using an HTTP interceptor to update the values before they hit the server? You should be able to catch the request to /postSave, then modify the data model.

    Not sure though if that will impact the displayed value in the data type

  • Nick 34 posts 127 karma points
    Jan 18, 2017 @ 16:21
    Nick
    0

    Yeah it seem like the only option I could do. I had to re render the datapicker to display the changes.

  • 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