Quick Tip: One CLI Command to Solve Your IAR Database Override Problems

> A life saver during development and initial golive
Cover Image for Quick Tip: One CLI Command to Solve Your IAR Database Override Problems

Background

IAR has numerous benefits, but it can cause a lot of problems if you or others tinker with items that are included in your IAR dat files. This is common during development and initial golive. The end result is that you may push item changes via source control, but the changes don't take because they have been overridden in the database. This often leads to much confusion and churn when pushing fixes/changes to templates, presentation, etc.

Over the years, we've seen custom modules, tools, and scripts for identifying and cleaning up IAR items that have been overridden in the database. However, there is a single CLI command that can be used to view and remove all IAR database overrides in one line.

Prerequisites

Before running the command, make sure you have:

  • The Sitecore CLI installed (dotnet tool install Sitecore.CLI)
  • The itemres plugin added: dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.ItemResource
  • An authenticated connection to your environment. The -n value (development below) refers to an environment defined in your user.json, so you'll need to log in first with dotnet sitecore login before the command can reach the instance

The Command

The Sitecore docs outline a single command that can do everything you need to perform analysis and cleanup of IAR database overrides. The full command is:

dotnet sitecore itemres cleanup -p "/sitecore/templates/Project" -n "development" -f -r -v -w

Where:

  • f = force
  • r = recurse
  • v = verbose
  • p = path
  • n = environment name (as defined in your user.json)
  • w = what-if

Run the what-if to see which items are overridden in the database, and then run the command without the w to remove them, scoped by path as you wish.

Approach

The parts of the tree I've seen the most issues with overrides are:

  • /sitecore/content/sites/ACME/Presentation
  • /sitecore/templates/Project/sites/ACME
  • /sitecore/layout/Placeholder Settings/Project/sites/ACME
  • /sitecore/layout/Renderings/Project/sites/ACME
  • /sitecore/content/sites/ACME/Settings/Standard Values

I recommend running the command on these paths once in a while, especially before a golive, to ensure that your IAR items are not overridden in the database.

One Last Step

After you perform the cleanup, you may need to clear the cache, restart the instance, and/or rebuild the sitecore_master_index.

Package.json Script

You can also add a script to your package.json to make it easier to run the command. For example:

{
"scripts": {
"itemres:cleanup:development": "dotnet sitecore itemres cleanup -n \"development\" -f -r -v"
}
}

Then you can run the command with:

npm run itemres:cleanup:development

GitHub Workflow

Below is an example workflow that you can add to your repository under .github/workflows/iar-cleanup.yml:

name: "Cleanup Item Resources"
# Manually triggered workflow that removes items stored in resource packages (Items-as-Resources)
# from the target environment's database via `dotnet sitecore itemres cleanup`. This is the CI
# equivalent of the local `npm run itemres:cleanup:development` script: because CI has no local
# `.sitecore/user.json`, it authenticates with client credentials and connects the cloud
# environment instead of using the named `development` connection. Defaults to what-if mode so a
# run previews the deletions without applying them; set WHAT_IF=false to actually clean up.
on:
workflow_dispatch:
inputs:
ENVIRONMENT:
description: Target environment
type: environment
required: true
PATH:
description: 'Sitecore item path or GUID to clean up (e.g. /sitecore/layout). Leave blank for the whole tree.'
type: string
required: false
RECURSE:
description: Recursively clean up all items under the path.
type: boolean
default: true
WHAT_IF:
description: Simulate the cleanup without deleting anything.
type: boolean
default: true
run-name: Cleanup Item Resources - ${{ inputs.ENVIRONMENT }}${{ inputs.WHAT_IF && ' (what-if)' || '' }}
jobs:
cleanup:
name: Cleanup item resources on ${{ inputs.ENVIRONMENT }}
runs-on: ubuntu-latest
concurrency: "${{ inputs.ENVIRONMENT }}-sitecorecloud"
environment: ${{ inputs.ENVIRONMENT }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- run: dotnet tool restore
- name: Authenticate CLI with Sitecore Cloud
run: dotnet sitecore cloud login --client-credentials --client-id ${{ vars.SITECORE_CLOUD_CLIENT_ID }} --client-secret ${{ secrets.SITECORE_CLOUD_CLIENT_SECRET }} --allow-write
- name: Connect to the Sitecore Cloud environment
run: dotnet sitecore cloud environment connect --environment-id ${{ vars.SITECORE_CLOUD_ENVIRONMENT_ID }} --allow-write
- name: dotnet sitecore itemres cleanup
# Inputs are passed through env (not interpolated into the script) to avoid shell injection,
# and assembled with a bash array so paths with spaces stay intact. `-f` is always sent so
# the what-if preview reflects exactly what a real (forced) run would delete.
env:
ENV_NAME: ${{ vars.SITECORE_CLOUD_ENVIRONMENT_NAME }}
ITEM_PATH: ${{ inputs.PATH }}
RECURSE: ${{ inputs.RECURSE }}
WHAT_IF: ${{ inputs.WHAT_IF }}
run: |
set -euo pipefail
args=(-n "$ENV_NAME" -f -v)
if [ -n "$ITEM_PATH" ]; then args+=(-p "$ITEM_PATH"); fi
if [ "$RECURSE" = "true" ]; then args+=(-r); fi
if [ "$WHAT_IF" = "true" ]; then args+=(-w); fi
echo "Running: dotnet sitecore itemres cleanup ${args[*]}"
dotnet sitecore itemres cleanup "${args[@]}"

Clean your room,

-MG

I chose these words

More Posts

Cover Image for Azure PaaS Cache Optimization

Azure PaaS Cache Optimization

> App Services benefit greatly from proper configuration

Cover Image for On Sitecore Development

On Sitecore Development

> Broadly speaking

Cover Image for NextJS: Short URL for Viewing Layout Service Response

NextJS: Short URL for Viewing Layout Service Response

> Because the default URL is 2long4me

Cover Image for Handy PowerShell Script When Working With Text Fields

Handy PowerShell Script When Working With Text Fields

> Quickly analyze freeform text field inputs