In the previous article, we mentioned that SharePoint is a workflow platform that encapsulates the event-driven interface on top of the WF workflow engine; SharePoint extends a lot of activity on WF, where three common activities that are closely related to WF are: ONWORKFL Owactivated,createtask,ontaskchanged.
A simple SharePoint sequential stream.
onWorkflowActivated: Responds to events initiated by the process.
CreateTask: Create a SharePoint task.
Ontaskchanged: Respond to events that have been changed by the task.
There can be only one onworkflowactivated in a process; there may be any number of createtask and ontaskchanged, but must be pairs;
Many SharePoint workflow solutions, in sequential streaming mode, make the CreateTask and ontaskchanged a custom activity, and then take advantage of Replicatoractivity's automatic replication to support multiple people approving simultaneously. This way the process is concise, but the sequential flow does not support the fallback, the situation needs to be rolled back, only through the whileactivity simulation, the process will become very complex.
A simple SharePoint state machine
The process includes three states to start, approve, and complete, and then add other states to achieve a fallback between states.
onWorkflowActivated and setstateactivity are included in response to startup events
The add approver includes the CreateTask
Ontaskchanged and Setstateactivity are included in the response approval event
Each stateactivity of WF can contain only one stateinitializationactivity, which is used to add approvers and implement the business logic for initialization. Can contain multiple eventdrivenactivity to simultaneously respond to multiple approval events and to implement the business logic after approval; EventDrivenActivity's first control must be handleexternaleventactivity ( The base class of the ontaskchanged).
As we can see from the image above, the createtask and ontaskchanged still have to be aligned under the state machine, but their positions are separated, createtask in stateinitalizationactivity, ontaskchanged is in the eventdrivenactivity.