Items as resources part 4 compare

24 May 2023, last update: 13 Feb 2024

Items as resources part 4 compare

When working with items as resources in Sitecore, it would be great to have a functionality that allows you to determine the changes between an overwritten resource item and the original resource item.

This blog post explains how to compare Sitecore items as resources and how to add the comparison functionality to the PowerShell report described in "Items as Resources by Sitecore - Part 2: Reports" and "Items as Resources by Sitecore - Part 3: Restoring".

 

Sitecore's out-of-the-box comparison functionality includes a resource item cleanup feature. Originally designed for database cleanup during upgrades, it can now be used in XM cloud to restore all items or only those that are identical. The easiest way to use this functionality is by using the Sitecore CLI (Command Line Interface), The

 

Build an overwrite resource item compare in Sitecore PowerShell

To build an overwrite resource item comparison in Sitecore PowerShell, we need a functionality that can compare specific items without relying on log file comparisons.

The process of comparing a resource item from a resource file with an item in the SQL Database involves iterating through the fields and comparing their values. Additionally, the reverse process can be used to identify any new fields.

Accessing the resource item requires opening the file in the same way as we did for the report. This is because Sitecore functionality is internal/private in the Sitecore.Kernel and not directly accessible. Within the resource file, fields are stored in two collections: one for shared fields and one for versioned fields. In the case of unversioned but language-specific fields, they are assigned version 0 in the resource file. Empty fields or those with default values do not exist in the resource file. You will find the source code on my Github.