Adding new property to doctype (content type) requires save and publish on all content nodes?
If I add a property to an existing content type, the default value is not applied to all the content using that content type. I have to save and publish each content item to get a default or explicit value. I tried rebuilding nucache but that doesn't work. I also tried save and publish using the content service but that also does not work.
Does anyone have any insight into how I can get new property default values saved to all affected content without re-publishing each one?
Then this event only fires just before the content item is displayed in the backoffice, and so each item requires to be loaded into the backoffice for that code to run.
It's hard to add a new property with a default value, to 'lots and lots' of existing content.
I'm going to guess though that you are adding a new Checkbox to your Document Type... this is because the UI for the Checkbox has a configuration setting called 'Default Value'... which can be True or False... however this is really misleading, as it isn't the 'default value' for this property when it's added to a Document Type... this is instead the 'default value' to present to an Editor for the checkbox when they create a new item in the backoffice....
... which doesn't help if you are say adding a new checkbox to every page to 'Display on Homepage', and you want the default value to be true...
You could use the ContentService, to iterate through each item - but just saving and publishing won't pick up the 'default' value for the checkbox because this is only a setting that applies to the 'default' state to display to the editor when it loads in the backoffice - but you could explicily set the value of the property and save and publish... future content items created in the backoffice, will have the default value...
But knowing this you 'can' workaround the limitation a little in code, by wording the intent of your Checkbox to mean that the absence of the Checkbox is the default choice.
So if you have a need for a 'Display on Homepage' checkbox with the default value true instead call it 'Hide from Homepage' - and in code use the absence of the property to mean the same as 'false'.
var hideFromHome = Model.HasProperty("hideFromHomepage") && Model.Value<bool>("hideFromHomepage");
Existing pages without the checkbox will therefore not be hidden from the homepage, the 'default' value - any page that should be hidden will need to have that checkbox set, and will require an editor to set it, which means the save and publish will update the published cache for that item and the page will be hidden.,..
sorry I've taken a big long guess at it being a checkbox! - but the workaround is similar for other properties, eg use the code to present the default value if the property is missing...
... and hopefully it gives you the insight into why it 'doesn't just work' as you would expect!
You were right about the checkbox :) In this case I can assume "true" if it's null. I was just wondering if there was a way around the issue to get an actual value into the database. Thank you so much for the quick and detailed answer!
Adding new property to doctype (content type) requires save and publish on all content nodes?
If I add a property to an existing content type, the default value is not applied to all the content using that content type. I have to save and publish each content item to get a default or explicit value. I tried rebuilding nucache but that doesn't work. I also tried save and publish using the content service but that also does not work.
Does anyone have any insight into how I can get new property default values saved to all affected content without re-publishing each one?
Hi Michael
What is the type of property you are adding, and how are you setting the Default value?
If you are setting the default value via the EditorModelEventManaging SendingContent event
https://our.umbraco.com/documentation/Reference/Events/EditorModel-Events/#usage
Then this event only fires just before the content item is displayed in the backoffice, and so each item requires to be loaded into the backoffice for that code to run.
It's hard to add a new property with a default value, to 'lots and lots' of existing content.
I'm going to guess though that you are adding a new Checkbox to your Document Type... this is because the UI for the Checkbox has a configuration setting called 'Default Value'... which can be True or False... however this is really misleading, as it isn't the 'default value' for this property when it's added to a Document Type... this is instead the 'default value' to present to an Editor for the checkbox when they create a new item in the backoffice....
... which doesn't help if you are say adding a new checkbox to every page to 'Display on Homepage', and you want the default value to be true...
You could use the ContentService, to iterate through each item - but just saving and publishing won't pick up the 'default' value for the checkbox because this is only a setting that applies to the 'default' state to display to the editor when it loads in the backoffice - but you could explicily set the value of the property and save and publish... future content items created in the backoffice, will have the default value...
But knowing this you 'can' workaround the limitation a little in code, by wording the intent of your Checkbox to mean that the absence of the Checkbox is the default choice.
So if you have a need for a 'Display on Homepage' checkbox with the default value true instead call it 'Hide from Homepage' - and in code use the absence of the property to mean the same as 'false'.
Existing pages without the checkbox will therefore not be hidden from the homepage, the 'default' value - any page that should be hidden will need to have that checkbox set, and will require an editor to set it, which means the save and publish will update the published cache for that item and the page will be hidden.,..
sorry I've taken a big long guess at it being a checkbox! - but the workaround is similar for other properties, eg use the code to present the default value if the property is missing...
... and hopefully it gives you the insight into why it 'doesn't just work' as you would expect!
regards
Marc
You were right about the checkbox :) In this case I can assume "true" if it's null. I was just wondering if there was a way around the issue to get an actual value into the database. Thank you so much for the quick and detailed answer!
is working on a reply...