0

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
  • 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(); Commented Feb 11, 2020 at 14:30

2 Answers 2

0

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);
workflow.GetCommands(currentWorkflowState.StateID);

to get current command from arguments

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

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 and acknowledge you have read our privacy policy.

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