28 January 2014

Sitecore GetItem not returning Restricted Items

Sitecore GetItem and GetChildren not returning Restricted Items

The problem

Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentNode= master.GetItem("ItemNAme");
var childItems=parentNode.GetChildren();
Only returned children that did not have Restricted Publishing, the same happend when using GetDescendends and FastQuery. Finally a trial with GetItem on a restricted item also gave a null...


Very useless if your job was to loop through a hierarchy and synchronize items and their publishing restrictions. We had seen the bug earlier but it had gone away with no explanation...

I tried several searchs

Came close on this one:

But it was first on the 5th coworker I showed the issue that he got the right google search going.

The Solution

When IsPreview is true (cookie based) and Filtering on the site config is allowed you will not get Items with publishing restrictions. This functionality is from the implementation of the PageEditor Preview where you need to browse the master database as if published items where not visible.

Stackoverflow saved my day:

Sitecore Publishable flag makes it impossible to GetItem() from Master database

No comments: