Copied to clipboard

Flag this post as spam?

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


  • David Armitage 508 posts 2077 karma points
    Oct 06, 2017 @ 14:14
    David Armitage
    0

    Umbraco Bug - Updating Document when multiTreePicker values are the same

    Hi,

    A strange one here. Umbraco version 7.6.5 assembly: 1.0.6428.37121

    1. I am updating a docType through code.
    2. The docType has multiple fields (indistries, locations, workTypes, keywords)
    3. The issue is happening with MultiTreePicker fields only.

    The issue happens when there has been no change to one of the multiTreePickers.

    If I change all the fields, add or remove items from the MultiTreePickers then they save fine.

    If for instance one of the MultiTreePickers values don't change then I run the save and publish (obviously to update other fields on the docType that have changed) then the values of the unchanged MultiTreePicker that are saved in-fact save some invalid value.

    To try and get around the issue I have tried.

    1. Only calling the SetValue() if something has changed. so this content.SetValue("industries",model.SelectedIndustries);

    would only get called if SelectedIndustries had infact been changed.

    This still had an error.

    1. I also tried to SetValue() to a blank string first and then run the SetValue() again to see if this triggered a change and tricked Umbraco into saving this correctly.

    This still didn't work.

    Has anyone experienced a similar issue? Is this possibly something to do with the xml cache? Should I be doing something extra following the save and publish?

    Here is my exact code

    public static IPublishedContent UpdateJobAlertSettings(JobAlertsUpdateForm model)
            {
                var contentService = ApplicationContext.Current.Services.ContentService;
                var content = contentService.GetById(model.SubscriberId);
    
                if(content != null)
                {
                    content.SetValue("industries", model.SelectedIndustries); //multitreepicker
                    content.SetValue("locations", model.SelectedLocations);  //multitreepicker
                    content.SetValue("workTypes", model.SelectedWorkTypes);  //multitreepicker
    
                    if (model.Keywords != null)
                    {
                        content.SetValue("keywords", BusinessManager.ListStringsToRepeatableTextString(model.Keywords.Split(new string[] { "," }, StringSplitOptions.None).ToList()));
                    }
                    else
                    {
                        content.SetValue("keywords", "");
                    }
    
                    content.SetValue("disableAlert", model.DisableAlert);
    
                    try
                    {
                        contentService.SaveAndPublishWithStatus(content);
                        return BusinessManager.GetPublishedContentById(content.Id);
                    }
                    catch
                    {
                        return null;
                    }
                }
    
                return null;
            }
    

    As a reminder if I change all the MultTreePicker values (industries,locations,worktypes) the save works fine. Its only if one of these 3 fields remains unchanged that the save doesn't work.

    The save and publish doesn't throw and error. Its seems to save fine but when I check in Umbraco backend the nodes haven't been selected and if I try to load these in the frontend it throws an error saying

    An exception of type 'System.FormatException' occurred in Umbraco.Core.dll but was not handled in user code
    
    Additional information: String "062b3adc7dba40d6908d49b271c81823" is not a valid udi.
    
  • David Armitage 508 posts 2077 karma points
    Oct 06, 2017 @ 14:32
    David Armitage
    100

    Hi,

    Ignore this I finally figure this out. It was related to a frontend issue. Some invalid was getting passed in to the save.

Please Sign in or register to post replies

Write your reply to:

Draft