Sitecore Query XPath for Finding all Locked Items

Summary

Do you need to find all items in Sitecore that have been locked by any user? Below is an XPath query that will show you just that. Keep in mind that depending on the number of items in your installation, this query could take quite a while. I would not recommend running it in your code in a production environment, but rather using the XPath Builder to find these items and resolving them manually.

/sitecore//*[@__lock!='' and @__lock!='<r />']

How Does it Work?

Let’s break down the components of the query:

/sitecore//*[@__lock!='' and @__lock!='<r />']

Start at the root of the content tree: the sitecore item.

/sitecore//*[@__lock!='' and @__lock!='<r />']

Look at all descendants (recursively check all children).

/sitecore//*[@__lock!='' and @__lock!='<r />']

Only return items whose __lock field is not empty and does not contain <r />, signifying that a lock has been cleared.

Issues or suggestions? Sound off in the comments.

Advertisements

5 Responses to “Sitecore Query XPath for Finding all Locked Items”

  1. Andy Cohen Says:

    Could you have done the same thing by using a SOLR query?

    • Dan Sinclair Says:

      Yes, you certainly could have. There is a field (lock) that is populated by the computed field Sitecore.ContentSearch.ComputedFields.IsLocked that is set to true when the item is locked. See below for the query you want:

      (lock:true AND _latestversion:true)

      The _latestversion:true part is important if you only want to return cases where the latest versions were locked.

  2. jammykam Says:

    There is also a report already available in Sitecore PowerShell Extensions for Locked Items, and it also allows you to restrict by user and date.

    https://sitecorepowershell.gitbooks.io/sitecore-powershell-extensions/content/reports.html

    It’s then very simple to extend this to Unlock the items as well.

  3. michaellwest Says:

    Thanks for sharing. Have you tried plugging this query in the Get-Item command found within Sitecore PowerShell Extensions?

  4. Jeff Says:

    Excellent work on getting that syntax correct. Xpath can be a pain to work with sometimes.

    Another option available is:
    https://marketplace.sitecore.net/Modules/A/Advanced_System_Reporter.aspx?sc_lang=en


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: