I worked on making a special module for Sitecore XM Cloud, combining items from both Core and Master, along with some DLLs and aspx files. While developing locally using XM Cloud with Docker, I created a custom container image for this module. I explained the process in one of my articles. However, I faced a challenge as the container image couldn't be used in the actual XM Cloud instance. Unlike our XP instance, you can't install the package using the Sitecore Installation Wizard.
After some research, I discovered that I needed to reference the module assets in my solution and then deploy it to the XM Cloud instance. This worked well for DLLs and other supported files, but I encountered an issue with items in Core and Master. I initially serialized the items and added them to the deployment steps. However, during deployment, I encountered the following error.
Configured source item path /sitecore/templates/RWS Module did not exist in serialized items (27 subtrees) data store. An empty source indicates that you need to fill that source with data before attempting to push it into a destination. Usually that means you need to pull an initial data set from Sitecore to fill serialized files before being able to push serialized data into Sitecore.
This error stated that this is expecting the items before it Push through SCS, but in my case it was the first time where items needs to be created. To resolve this issue I researched quite a bit and found out that in this scenerio we need to convert item as resource file and then use it on the XM Cloud.
What is Item as Resources (IAR) Plugin?
Items as Resources is a capability that extends the possible sources for Sitecore items. It lets you load a subset of items from precompiled resource items on disk and merges them into the user-visible content tree.
Items are still loaded and presented in the content tree and work just like regular Sitecore items. When you make a change and save, it copies the entire item to the content database.
This functionality supports and simplifies several scenarios:
Continuous integration and container-friendly deployment
Disk-only installation of modules with easy composition and support for uninstallation
Continuous integration scenarios for solution developers with blue-green deployment of code and definition items together
Version upgrades
How does IAR Plugin works?
The Sitecore Items as Resources Plugin includes an itemres command. This command creates an item package in a resource file with configurable options based on the settings from the *.module.json which will be used for Sitecore Content Serialization by Sitecore CLI.
To install the Items as Resources plugin, run the following code on your project folder
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.ResourcePackage
To verify if the plugin has been installed, run the following command
dotnet sitecore plugin list
To produce the IAR file, execute the following command. Ensure that your items are listed in the *.module.json file, as these items will be converted into IAR format, resulting in .dat files.
dotnet sitecore itemres create -o itemres/rws
The command mentioned above will transform the items specified in *.module.json and save the resulting .dat file in the "itemres" folder, created at the project file's root. If the items are in the master database, the .dat file will be named items.master.module.dat. The same naming convention applies to items in the Core and Master categories.
If the .dat file has already been generated, you can update it by including the --overwrite parameter in the command mentioned earlier. To explore additional parameters for the itemres command, please refer the official documentation.
To know more about the Sitecore Content Serialization please refer following sites
How to convert the Item as Resources file to actual Sitecore Item in XM Cloud?
After converting the items into a .dat file, the next step is to transform the .dat file back into the actual items. To accomplish this, copy the .dat file to the specified location within the Platform project or website project.
items.master.module.dat - App_Data/items/master
items.core.module.dat - App_Data/items/core
items.web.module.dat - App_Data/items/web
Once you've finished the aforementioned steps, initiate a new deployment to your XM Cloud instance. This process will seamlessly transition the items from the .dat file to items in Sitecore. Any modifications made to these items will be automatically saved on the item itself.
Happy Sitecoreing!!
References:
https://doc.sitecore.com/xp/en/developers/103/developer-tools/items-as-resources-plugin.html
https://doc.sitecore.com/xp/en/developers/103/developer-tools/the-cli-itemres-command.html
https://konabos.com/blog/generating-your-own-custom-iar-files-of-your-sitecore-items
https://pushpaganan.home.blog/2023/02/18/sitecore-item-as-a-resource-deep-dive-1-iaar-plugin/
https://www.sitecorespark.com/blog/2022/10/how-do-sitecore-modules-work-with-sitecore-xm-cloud-
Comments