Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Content type property sort order not updated during model synchronization

Ted
Ted
Vote:
 

It it just me, or are sort orders for content type properties no longer being updated during model synchronization?

I'm on the latest version, but changes to the Order property of a Display attribute isn't reflected in the database.

Notice how the sort order in the database is still 0, despite having been changed to 200 in code:

(This is with latest package versions at time of writing, EPiServer.Framework 12.4.0)

#275800
Mar 07, 2022 7:54
Vote:
 

I have noticed this as well. And it's no longer possible to delete properties that are removed in code from the admin UI as far as I can see.

#275801
Mar 07, 2022 9:14
Scott Reed - Mar 07, 2022 9:34
That should have been fixed in the release on the 22nd of Feb as far as I know https://world.optimizely.com/forum/developer-forum/Problems-and-bugs/Thread-Container/2022/1/cms12-cannot-delete-property-that-once-was-in-code/
Ted - Mar 07, 2022 10:00
"Glad" it's not just me. :) Updating EPiServer.CMS.Core to 12.4.0 fixes the problem with not being able to delete removed properties, but the sort order problem appears to be a bug still.
Chris Sharp - Mar 08, 2022 1:18
I also had some issues after updating to the 12.4.0 release, but they were related to the [CultureSpecific] decoration. For the specific content type property, I ended up deleting the property all together, making sure it was cleared out of the system, and re-added the property, and finally the issue went away. Might be worth trying.
Vote:
 

This is also not working in the latest version of CMS 11

I read in another thread that if anyone changes the sort order of a single property on a content type, it will not sync anymore with the code until the "revert to default" button  is clicked on each property.

This code was linked in that thread (that i cant find again for some reason), I have not tested this code, so use at your own risk:

            var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
            var propertyDefinitionRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();
            var myPages = contentTypeRepository.List();

            foreach (var myPageType in myPages) {
                foreach (var prop in myPageType.PropertyDefinitions) {
                    var writable = prop.CreateWritableClone();
                    writable.ResetPropertyDefinition();
                    propertyDefinitionRepository.Save(writable);
                }
            }

Edit: I made a modification for myself to just reset the sort indexes using some reflection, as the resetpropertydefinition call will reset everything, including custom property settings and such, the below only resets the sort index:

            var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
            var propertyDefinitionRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();
            var myPages = contentTypeRepository.List();

            foreach (var myPageType in myPages) {
                foreach (var prop in myPageType.PropertyDefinitions) {
                    var writable = prop.CreateWritableClone();
                    writable.GetType().GetProperty("NullableFieldOrder", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
                        .SetValue(writable, null, null);
                    propertyDefinitionRepository.Save(writable);
                }
            }
#300488
Edited, Apr 21, 2023 6:57
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.