4

I have item with publishing restrictions. After apply restriction for item I see that in Livetime section Valid From and Valid To fields was set. It's ok.

But when I'm trying to get item by id:

Sitecore.Context.Database.GetItem(itemID)

where Sitecore.Context.Database is master - I couldn't get this item, but I can search item by id in Content Editor search.

When I will remove publishing restrictions and clear Valid From and Valid To fields - I will receive my item.

Could you explain me:

How Valid From and Valid To fields affect get item from master db?

Sitecore 8.1 Update-3

3

This has to do with how the data providers work in Sitecore and as mentioned in the linked SO post above, is useful for distinguishing "preview" modes.

If you enable what in Sitecore is known as "Live Mode", this is what it does.

From LiveMode.config.disabled in a vanilla Sitecore installation:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <sites>
      <site name="website">
        <patch:attribute name="database">master</patch:attribute>
        <patch:attribute name="filterItems">true</patch:attribute>
        <patch:attribute name="enableWorkflow">true</patch:attribute>
      </site>
    </sites>
  </sitecore>
</configuration>

filterItems

This setting specifies whether Live Mode will filter out items that have publishing restrictions.

This is what is filtering your items in your example. Valid From and Valid To are publishing restrictions.

enableWorkflow While not in your example, Sitecore would also return NULL for items that are in a workflow state that is not final. This setting toggles that behaviour.

What I normally do locally, is have 2 sites configured, pointing to my "master" database. One which is "normal" and one running true Live Mode.

You could do the same, or just add the above 2 attributes to your site definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.