Updating property values in multilevel nested contents
Updating property values in multilevel nested contents
We have a document type named "ContentPage" and it has a property that uses the same "ContentPage" as nested content. It has multiple levels(let's say 3 levels) and I need to update a property value in that lower level (in level 3).
We tried looping the content as "IPublishedContent" and I was able to reach the property values. but after doing the changes to the property values We were unable to set that values to nested content using the "SetValue" method since it is not available in "IPublishedContent". We tried to convert the "IPublishedContent" to "IContent" object but it seems not possible. Nested contents also missing id, parent, nodeId properties. so it is hard to track the content with the outer most content.
so is there any way to loop the nested content and set values to the properties in a particular nested content when we are in that content itself?
This is running as a background task and it is recursively going down on the nested tree and plan is to update the values in each level and serialize it and return it to the upper level. then on the outermost content page, we can publish the properties of that outer content page by fetching it as "IContent" using contentservice and updating values to values returned by the lower nested levels. so then nested contents will be updated as expected.
If anyone has worked on things like this please share your idea about this and if anything is not correct in this approach please suggest a correct workaround.
For any CRUD operations you can't use IPublishedContent as that is just a read-only cache version of the content - you will have to use the ContentService.
Nested Content is saved as a json blob in the database - you can try to find examples in the umbracoPropertyData table in the db - the reason you can get a nested content object as IPublishedContent using the cache is because there are Property Value Converters that can extract the IPC model from the json and generate the proper models for you - however this doesn't happen when using the contentservice so any changes you may want to make has to be made in the json blob.
Haven't tried working with this myself - especially the multiple nested objects is likely to make this a bit complicated - but I'd recommend you try to first get the page through the contentservice and then print out what the value of the property is - then you'll need to somehow update the JSON to fit your requirements.
Updating property values in multilevel nested contents
Updating property values in multilevel nested contents
We have a document type named "ContentPage" and it has a property that uses the same "ContentPage" as nested content. It has multiple levels(let's say 3 levels) and I need to update a property value in that lower level (in level 3).
We tried looping the content as "IPublishedContent" and I was able to reach the property values. but after doing the changes to the property values We were unable to set that values to nested content using the "SetValue" method since it is not available in "IPublishedContent". We tried to convert the "IPublishedContent" to "IContent" object but it seems not possible. Nested contents also missing id, parent, nodeId properties. so it is hard to track the content with the outer most content.
so is there any way to loop the nested content and set values to the properties in a particular nested content when we are in that content itself?
This is running as a background task and it is recursively going down on the nested tree and plan is to update the values in each level and serialize it and return it to the upper level. then on the outermost content page, we can publish the properties of that outer content page by fetching it as "IContent" using contentservice and updating values to values returned by the lower nested levels. so then nested contents will be updated as expected.
If anyone has worked on things like this please share your idea about this and if anything is not correct in this approach please suggest a correct workaround.
For any CRUD operations you can't use IPublishedContent as that is just a read-only cache version of the content - you will have to use the ContentService.
Nested Content is saved as a json blob in the database - you can try to find examples in the umbracoPropertyData table in the db - the reason you can get a nested content object as IPublishedContent using the cache is because there are Property Value Converters that can extract the IPC model from the json and generate the proper models for you - however this doesn't happen when using the contentservice so any changes you may want to make has to be made in the json blob.
Haven't tried working with this myself - especially the multiple nested objects is likely to make this a bit complicated - but I'd recommend you try to first get the page through the contentservice and then print out what the value of the property is - then you'll need to somehow update the JSON to fit your requirements.
is working on a reply...