Sitecore 8.2 Update 5

Kind of at a real loss here. Should be really simple code, just can't get the commands. In the code below workflow and workflow2 are not null and is the correct workflow.

In command, I am getting the commands for the current item's FieldIDs.WorkflowState. No commands are returned.

In command2, I am calling the state directly by ID. Still no commands are returned.

var database = Sitecore.Configuration.Factory.GetDatabase("master");

var workflow = database.WorkflowProvider.GetWorkflow(item);
var command = workflow.GetCommands(item[FieldIDs.WorkflowState]); 

var workflow2 = database.WorkflowProvider.GetWorkflow("{6AC12F8A-9374-41A3-B2D9-DBC7C9A0FB73}");  
var command2 = workflow2.GetCommands("{8B439291-76EE-46D2-ACEE-2BC67142D35F}");
  • If you try: var command = workflow.GetCommands(item[FieldIDs.WorkflowState]).FirstOrDefault(); Do you get a result? Sep 6 '18 at 20:59
  • @JonFairchild No its an empty result
    – Chris Auer
    Sep 6 '18 at 21:01
  • By the way, just to clarify, what version of Sitecore are you on? Sep 6 '18 at 21:02
  • Sorry, updated question. Sitecore 8.2 Update 5
    – Chris Auer
    Sep 6 '18 at 21:07
  • IWorkflow workflow = item.Database.WorkflowProvider.GetWorkflow(item); if (workflow == null) return new WorkflowResult(false, "No workflow assigned to item"); WorkflowCommand command = workflow.GetCommands(item[FieldIDs.WorkflowState]) .FirstOrDefault(); if (command == null) return new WorkflowResult(false, "Workflow command not found"); What does that get you? Sep 6 '18 at 21:12

This one gets filed under the "doh" column. The user who is doing this action did not have access to the workflows. When I switched to SecurityDisabler(). The commands show up. This is a self service app where a user logs in with a limited Sitecore user to edit some content.

Thanks for the help Mark and Jon.


Your context site needs to have Workflow enabled

For any Workflow functionality to work, you must be in the context of a site that has it enabled. By default, this would only be the "shell" site.

Your code and question does not mention what site context you are currently in, but I am assuming since you're requesting:

var database = Sitecore.Configuration.Factory.GetDatabase("master");

that you are in a Site Context other than "shell" which would have this database by default. Asking for "master" by magic string is a nasty habit by the way, but let's leave that for now.

Either force your Site Context to "shell" using a SiteContextSwitcher or enable workflows on the context site you are running. Add enableWorkflows="true" to the <site> element for the site.

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.