Items/Templates changes in serialization files are not getting reflected on Sitecore XM Cloud after build

Items/Templates changes in serialization files are not getting reflected on Sitecore XM Cloud after build - Essentially, It's because of the way XM cloud stores data. Sometimes as Resources and Sometimes as Database


Read below to learn more about Resources and Database  or Skip directly to the Solution Section


Scenario - Recently, we had to update source queries for few fields in some of our templates. 


We checked in our template changes in serialization files, triggered the build, but those changes were not getting reflected on XM cloud. Our template fields still had the old queries.


Root cause:


Sitecore XM cloud stores data in two ways - Resources ,also known as, IAR (Items as Resources) and Database, contrary to times when Sitecore only use to store data in Database.


In XM cloud the default Sitecore items are stored in resource files. 


If you edit an item directly in XM Cloud, Sitecore copies the item to the Database using the same item ID, then applies any future changes, to this database item.


The change is persisted in the database and is handled prior to the underlying file (IAR), meaning Sitecore would read the item from the database now and any change to resource file is ignored. 


Hence, any source code changes to that same item/template field would never be applied. 


This makes sense because few days ago, before we noticed this issue, we had created a workflow and assigned that workflow to our templates using PowerShell directly on XM Cloud. 


Hence, all those templates changed from Resources to Database and any change in serialization files were being ignored.


You can see whether an item is stored as Database or Resources in XM Cloud, by following below steps after enabling Developer tab:




















The Solution:


To fix the issue you need to revert an item stored as Database to Resources.


You can revert an item stored as Database to Resources by just deleting the item (if that item is present in serialization files) and the item would be restored from Resources.


But, when it comes to a template, you don't always have a privilege to delete a template, because you might have items already created in your content tree using that template.


In that case, you can use the Sitecore Items as Resources plugin which includes an itemres command.


If you have used Sitecore's starter foundation code, open PowerShell in your local system, go to the  local-containers path in your local system where you have cloned the repository, and Login to your XM Cloud Environment using below command.


dotnet sitecore login --authority https://auth.sitecorecloud.io --cm https://yourcmurl.sitecorecloud.io --audience https://api.sitecorecloud.io --allow-write true --client-credentials true --client-id yourclientid --client-secret yourclientsecret


To get Client ID and Client Secret, please follow this:


https://doc.sitecore.com/xmc/en/developers/xm-cloud/manage-client-credentials-for-an-xm-cloud-organization-or-environment.html#create-an-automation-client-for-an-xm-cloud-organization


Then run the whatif(-w) command in desired path to see the affected items.

This simulates items cleanup without actually cleaning up items.


-r is used to recursively cleanup all items under the specified path.


-f Force items cleanup without field comparison


dotnet sitecore itemres cleanup --path "/sitecore/templates/yourpath" -f -r -w








Once you analyze the items that would be affected, you can remove the -w parameter and run the actual command


Please be vcareful while running below changes as it would override the manual changes which were done on items/templates


dotnet sitecore itemres cleanup --path "/sitecore/templates/yourpath" -f -r


You would see that the changes are getting reflected in XM Cloud.


BTW, it works for content items as well.


I'll be posting more about Sitecore XM Cloud in future posts.
Stay tuned and Keep Learning :)

References:
More Info on Itemres

ArreyNitesh
Email - arreynitesh@gmail.com
Post a Comment (0)
Previous Post Next Post