I have created a sample workflow. In this workflow I have multiple states like Draft, Awaiting approval and Done. Each and every state have a command like submit, approve or reject.

I got my current state from workflow using below code

 IWorkflow workflow = workflowProvider.GetWorkflow(args.DataItem[FieldIDs.Workflow]);
   var currentWorkflowState = workflow.GetState(args.DataItem);

Now, I want the current command of the state.

but I got all commands from workflow using below code

var currentWorkflowState = workflow.GetCommands(args.DataItem);

Kindly assist, Thanks in advance

  • 1
    by the current command, you mean the first command under the workflow state, correct? try - var command = workflow.GetCommands(args.DataItem[FieldIDs.WorkflowState]).FirstOrDefault(); Feb 11, 2020 at 14:30

2 Answers 2


I hope your above code might have executed inside an action class. So you may able to get the Command Item from Workflow Pipeline arguments like how you got current state.

to get list of commands in your current state

var currentWorkflowState = workflow.GetState(workflowActionArgument.DataItem);

to get current command from arguments

public void Process(WorkflowPipelineArgs workflowActionArgument)
    Item commandItem = workflowActionArgument.CommandItem;
  • Thanks, Gopinath. Yes, I got it. Get current command name from var commandItem = workflowActionArgument.CommandItem.Name Feb 12, 2020 at 6:39

You need to pass proper value to workflow.GetCommands method.

It should be WorkflowCommand command = workflow.GetCommands(workflowStateID).ToList();

workflowStateID should be ID of workflow state which you want to get commands for.

See disassembled code from Sitecore.Kernel.dll:

enter image description here

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.