10
votes

Right now i'm having a problem with sitecore workflow. The issue is as follows:

my template standard value has set the Workflow and Default Workflow fields set. The workflow state is set to draft. However, everytime i create an item from this template it is not inheriting the workflow section fields, all of them are empty

if i manually set workflow and workflow state for items, it works as expected up to the final state. However, if a content author edits the item, a new version is created but only the workflow field value is kept, while the workflow state is again empty.

what i'm doing wrong? why is this happening? I'm using sitecore 6.5.0

2

2 Answers

23
votes

The __Standard Values of your template should only have the Default workflow field set; do not set the Workflow field on the __Standard Values item as that insinuates that the __Standard Values item is itself in the workflow! Similarly, do not set the State field on the __Standard Values item as that is saying that the __Standard Values item is in that state!

Your Workflow item has an Initial State field on it that defines the initial state an item will be in (assuming the item uses that workflow).

When you create an item, and that item has a __Standard Value with a workflow in the Default Workflow field, then that item will have its Workflow field set the same as the Default Workflow field of its __Standard Values. The state the item is in will be the Initial State as defined on said workflow.

3
votes

When you create the item via the API you appear to have to specifically set the workflow and the state explicitly:

Item myItem = parentItem.Add("New item", myTemplate);
myItem.Editing.BeginEdit();
// set any other fields you want here
...
// Now explicitly set the workflow and state here on your new item
// (make sure you get the correct GUIDs by viewing raw values on your workflow and workflow state items)...
myItem[FieldIDs.Workflow] = "{212BCCCB-8197-45C0-81CC-621E0553C25F}";
myItem[FieldIDs.WorkflowState] = "{E8228D86-D780-4F34-B372-6A4D29B67AF9}";
myItem.Editing.EndEdit(); 

I'm assuming that when you do it through the UI there are some extra pipelines that get processed that do this for you when using Content Editor etc, which you bypass by using the API.

In fact, here is a relevant post on SDN: http://sdn.sitecore.net/Forum/ShowPost.aspx?PostID=45991