2
votes

I am currently working with sitecore items that are in a draft workflow state. The following happens:

  • Create an item that will go into workflow draft state
  • Publish the item/publish the parent item (with sub items selected) to the web db from master db, ignore publish warning prompt
  • The item will appear in the web database but with no versions

This causes our controls to render the item but with standard values because there are no versions. Of course we could add a check for item.Versions.Count > 0 but my question is why this is happening?

Surely an item in draft workflow state should never appear in the web database in any way?

The workflow being used is pretty standard and has no customisation. The states and commands are:

  • Draft
    • Submit
  • Awaiting approval
    • Reject
    • Approve
      • Validation action
  • Approved
    • Auto publish

Thanks in advance.

4
To clarify, when you view the draft language version of an item, do you get the "This won't publish" warning message? Then when you publish that exact version, the item appears in the web DB?Martin Davies
Yes you are correct :)Jacob Francis

4 Answers

1
votes

I believe you can use the following property on each of your site nodes in the config.

<site name="website" filterItems="true" ... />

If setting this to true doesn't resolve the issue then you can add the following pipeline step, in addition to the above setting, before the Sitecore.Pipelines.FilterItem.EnsureFilteredItem step.

public class HideEmptyItem
{
    public void Process(FilterItemPipelineArgs args)
    {
        if ((Context.Site != null && Context.Site.DisplayMode == DisplayMode.Normal) && args.Item.Paths.Path.StartsWith("/sitecore/content/"))
        {
            try
            {
                Context.Site.DisableFiltering = true;
                if (args.Item.Database.GetItem(args.Item.ID, Context.Language).Versions.Count == 0)
                {
                    args.FilteredItem = null;
                }
            }
            finally
            {
                Context.Site.DisableFiltering = false;
            }
        }
    }
}

Also ensure the following is set accordingly, the default is false;

<setting name="Publishing.PublishEmptyItems" value="false" />

I actually encountered this issue but in a different way. If you use publishing restrictions you can end up with an item that has no versions on it but can still be published. There are many ways for an item to end up with no versions, not just a new item with a single version that hasn't been pushed through a workflow. The above fix was actually provided by Sitecore support and worked for me.

If this doesn't work for you then I would suggest adding in check when items are published to see if they have any versions, although I believe that's what the fix above is supposed to do.

EDIT: Changed property from "hideEmptyItems" to "filterItems" and added further explanation.

1
votes

My personal opinion is that you should be checking for version count. If you plan on ever supporting a multilingual site, it is entirely possible to have a version in one language, but not another (not approved yet in Spanish, for example). You would want your controls to handle that scenario (or execute fallback).

It is entirely valid that the current user in the current language may have no valid versions come back for them. I would expect that the business logic of the web controls should handle those scenarios.

1
votes

To explicitly answer your question, this happens because the item is not null but it has no versions. A version is a dimension of an item and it happens to be "empty" if you have no version. So your code gets a valid non null item, but has no field values since there is no version and thus your controls don't fill with data.

This will only happen for new items. Example: create an item and you have v1 which is is in draft. You "publish" the item. The item goes out to the web DB but the v1 dimension of it does not, so you're left with a non null item with no versions.

As Jay said, the solution is to check for this when you query items.

0
votes

First, the default workflow should set to the item's template "__Standard Values".
Second, workflow with "admin" account doesn't work. Try another account.