Workflow event

Apr 28, 2010 at 7:34 PM
Edited Apr 28, 2010 at 7:37 PM

I am trying to build workflow 4.0 using the state machine. WF Version 3.0 events can be dragged on a workflow state and externally we were able to invoke those events. I developed a workflow 4.0 using different state. How can I execute workflow 4.0 using different states? Do I need to maintain bookmarks under different state? 

Apr 29, 2010 at 4:24 AM

I assume that you used a StateMachine with multiple states. For your specific question "Do I need to maintain bookmarks under different state?": No, it's not necessary. Trigger can be any activity. You could use Delay, Receive or other activities as Trigger. You can also use your own customized activities which may use bookmarks.

The execution logic of StateMachine would look like as belowing. Here is a simple, uncomplete description for your first look and it doesn't include nested state case.  Please refer to user doc for more detailed description. If there is still something unclear, please let me know.

1. Execute intial State of StateMachine

  • Execute Entry of initial State
  • Execute Triggers of transition of initial State
  • Wait Triggers to be triggered

2. When any Trigger is triggered

  • Evaluate the condition of corresponding transition
  • If the condition is true or null, take corresponding transition
  • If the condition is false, evaluate other conditions ( if any)
  • If all conditions are false, reschedule the trigger

3.  Take corresponding transition

  • Execute Exit of the source State
  • Execute Action of the transition

4. Execute the target State (just like step 1 for initial State)

Apr 30, 2010 at 2:18 AM

Thanks that information was useful. Currently I am trying to build an Approval workflow using the state machine. A user raises a purchase request (State A - Initialize) and the manager needs to approve the request (State B - NeedsApproval). Trigger from Sate A to State B is a code activity. Once the manager approves the purchase request, I need to invoke the trigger for State B. I am aware of invoking the state machine using the WorkflowInvoker.Invoke, but not able to find how I can involve the trigger (code activity) which is the part of the state machine. Can you let me know how I can Invoke the trigger (code activity).

May 2, 2010 at 5:56 AM

In WFv2 we recommend using WF services to communite with the WF, and in State Machine's case, trigger state transitions.  So a possible way of implementing your State Machine could be:

State A listens for purchase request: you put a Receive activity in the trigger of a transition.  Once you receive the message and validate it's a valid purchase request, the transition is commenced and you're moved to State B to wait for manager approval

State B listens for manager's approval: again you can put a Receive activity (or some other control flow activity such as Pick that uses Receive in one of its triggers) in the trigger to listen for manager's respsone.  You can put a condition on the transition such that if the response is "approved", you transition to State C, and if not, you go to State D, etc. 

If you take this approach, you need to use WorkflowServiceHost to host your workflow, instead of WorkflowInvoker.

May 4, 2010 at 1:43 AM
rizwanf wrote:

Thanks that information was useful. Currently I am trying to build an Approval workflow using the state machine. A user raises a purchase request (State A - Initialize) and the manager needs to approve the request (State B - NeedsApproval). Trigger from Sate A to State B is a code activity. Once the manager approves the purchase request, I need to invoke the trigger for State B. I am aware of invoking the state machine using the WorkflowInvoker.Invoke, but not able to find how I can involve the trigger (code activity) which is the part of the state machine. Can you let me know how I can Invoke the trigger (code activity).

 The trigger is automacitally scheduled when you enter a state so techincally you don't need to invoke it. But according to your scenario, I would recommend you use the "manager approves the purchase request" as the trigger and the code activity as the action of the transition. I think you can model the "manager approve" logic using a Receive activity.

May 27, 2010 at 12:42 PM

I think this execution explanation should be part of the user guide. I Found it very usefull.

Jan 9, 2011 at 7:07 PM

Hi,

I believe I am trying to do what is described in your response.  Actually, I am using the 'ReceiveAndSendReply' template that is provided in the VS2010 ToolBox to trigger a state transition. 
Using the VS Workflow designer, I dragged a 'ReceiveAndSendReply' template into the transition area between State1 and State2.

I am now trying to discover this WCF service from another project within the same solution (so that I can call the WCF operation to trigger the state change).

However, this service operation does not show up, so obviously I am doing something wrong or misunderstand what needs to be done here. 

How do I call this 'Receive activity' to make this state change transition trigger work?

thanks

Jun 21, 2011 at 8:14 AM

Ideally, you would place the "receive" in the "Trigger" area of the Transition Designer, use the "Context Menu" of "Receive" and generate a "SendReply".  Go to the Action area of the transition and plast the "SendReply" activity there.