SharePoint workflow solution (2): WF state machine in SharePoint

Source: Internet
Author: User

In the previous article, we mentioned that Sharepoint is a workflow platform that encapsulates event-driven interfaces on top of the WF workflow engine. SharePoint expands many activities on WF, among them, there are three common activities closely related to WF: onworkflowactivated, createtask, and ontaskchanged.

A simple SharePoint Sequential stream.

 

Onworkflowactivated: responds to the Event initiated by the process.
Createtask: generate a Sharepoint task.
Ontaskchanged: the event in which the task is changed.

There can be only one onworkflowactivated in a process; there can be any number of createtask and ontaskchanged, but they must be paired;

Many SharePoint workflow solutions make createtask and ontaskchanged a custom activity in sequential flow mode, and then use the automatic copy function of replicatoractivity to allow multiple users to simultaneously approve the event. This method is simple, but the Sequential stream does not support rollback. When a rollback is required, it can only be simulated by whileactivity, and the process becomes complicated.

A simple SharePoint state machine

The process includes three statuses: Start, approve, and finish. You can roll back between statuses by adding other statuses.

Onworkflowactivated and setstateactivity are included in the response to the startup event.
Createtask is included in "add approver"
Ontaskchanged and setstateactivity are included in the "response approval event ".

Each stateactivity of WF can only contain one stateinitializationactivity, which is used to add approvers and implement initialized business logic. Multiple eventdrivenactivities can be contained to respond to multiple approval events at the same time and implement the business logic after approval. The first control of eventdrivenactivity must be handleexternaleventactivity (the base class of ontaskchanged ).

We can see that in the state machine, createtask and ontaskchanged must still be paired, but their locations are separated. createtask is in stateinitalizationactivity, and ontaskchanged is in eventdrivenactivity.

SharePoint state machine that can be simultaneously approved by multiple people

If multiple users need to approve the request at the same time, add multiple createtask in stateinitializationactivity, and add multiple eventdriven in stateactivity.

"Add approver" includes createtask of A and createtask of B.
The ontaskchanged of A is included in the "response to a's approval event.
The "response to B's approval event" contains B's ontaskchanged.

To add more approvers, and so on.

Problems with SharePoint state machine Workflow
From the above we can find that the state machine application of SharePoint has the following two problems:
1. The process in eventdrivenactivity is redundant. It is difficult to maintain the process when the process is complex and there are many approvers.
2. The number of approvers must be determined during the design period and cannot be changed.

In the previous article, we mentioned that Sharepoint is a workflow platform that encapsulates event-driven interfaces on top of the WF workflow engine. SharePoint expands many activities on WF, among them, there are three common activities closely related to WF: onworkflowactivated, createtask, and ontaskchanged.

A simple SharePoint Sequential stream.

 

Onworkflowactivated: responds to the Event initiated by the process.
Createtask: generate a Sharepoint task.
Ontaskchanged: the event in which the task is changed.

There can be only one onworkflowactivated in a process; there can be any number of createtask and ontaskchanged, but they must be paired;

Many SharePoint workflow solutions make createtask and ontaskchanged a custom activity in sequential flow mode, and then use the automatic copy function of replicatoractivity to allow multiple users to simultaneously approve the event. This method is simple, but the Sequential stream does not support rollback. When a rollback is required, it can only be simulated by whileactivity, and the process becomes complicated.

A simple SharePoint state machine

The process includes three statuses: Start, approve, and finish. You can roll back between statuses by adding other statuses.

Onworkflowactivated and setstateactivity are included in the response to the startup event.
Createtask is included in "add approver"
Ontaskchanged and setstateactivity are included in the "response approval event ".

Each stateactivity of WF can only contain one stateinitializationactivity, which is used to add approvers and implement initialized business logic. Multiple eventdrivenactivities can be contained to respond to multiple approval events at the same time and implement the business logic after approval. The first control of eventdrivenactivity must be handleexternaleventactivity (the base class of ontaskchanged ).

We can see that in the state machine, createtask and ontaskchanged must still be paired, but their locations are separated. createtask is in stateinitalizationactivity, and ontaskchanged is in eventdrivenactivity.

SharePoint state machine that can be simultaneously approved by multiple people

If multiple users need to approve the request at the same time, add multiple createtask in stateinitializationactivity, and add multiple eventdriven in stateactivity.

"Add approver" includes createtask of A and createtask of B.
The ontaskchanged of A is included in the "response to a's approval event.
The "response to B's approval event" contains B's ontaskchanged.

To add more approvers, and so on.

Problems with SharePoint state machine Workflow
From the above we can find that the state machine application of SharePoint has the following two problems:
1. The process in eventdrivenactivity is redundant. It is difficult to maintain the process when the process is complex and there are many approvers.
2. The number of approvers must be determined during the design period and cannot be changed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.