SharePoint workflow solution quickflow series (5)-tag (multitask and grouptask)

Source: Internet
Author: User

There may be many interpretations or definitions of signatures. The signatures mentioned in this Article refer to operations in a process that involve multiple users at the same time. These user interfaces are generally the same.

Quickflow signatures are implemented through multitask. multitask implements the logic for simultaneous assignment of multiple tasks. It has the following control attributes:

1)Executiontype-- Specify whether the task is allocated in a serial or parallel manner. If the task is serialized, the previous user completes the task and assigns the task to the next user. if the task is in parallel, all tasks are allocated at the same time.

2)Completionmode-- The task completion mode can be requireone and requireall. If requireone is used, no matter how many tasks are assigned in this step, once one user completes, the step ends, incomplete tasks are automatically canceled. If requireall is specified and completerule is not specified, all users are required to complete the task.

3)Completerule-- Completerule is a condition type attribute, which can be codeconditon or declareruleconditon. When completionmode is requireall, you can use completerule to further control when the approval process ends. We often encounter the following business scenarios: when multiple people participate in the approval, everyone agrees to the next step. If one user does not agree, the process is returned or ended, even if other users have not approved the application. In this case, you can use completerule.

The following is an example:

The process is very simple. In the first step, multiple people will sign the approval. If one person does not agree, the process will be completed. If all people agree, the approval will be sent to the Manager.

Step 1)Draw the following flowchart

The "start" Node corresponds to the start activity, the "sign for approval" corresponds to the multitask activity, the "Manager for approval" corresponds to the task activity, and the "end" corresponds to the end activity.

Note: If you have drawn the line in the flowchart and modified the activity name, you may need to delete the line and redraw it. Otherwise, the activity cannot be found.

Step 2)Process "sign approval"

Specify the completionmode for approval as requireall and executiontype as parallel.

Bind the taskoutcomes attribute of "sign for approval" to the workflow field:

Handle the initialized event of "sign for approval:

Private void will sign approval _ initialized (Object sender, eventargs E)
{
This. will sign for approval. Users. Add ("DC \ user1 ");
This. will sign for approval. Users. Add ("DC \ user2 ");
This. will sign for approval. Users. Add ("DC \ user3 ");
// If the task is assigned in serial mode, the order of task allocation is determined here.
}

Set the "sign for approval" completerule:

 

Note: This condition is true as long as the approval result of one person is reject.

Step 3)Set route judgment after "sign for approval"

Set demo-conditon to code conditon:

Private void allagree (Object sender, conditionaleventargs E)
{
E. Result = This. will sign for approval. taskoutcomes. Filter ("reject") = 0; // if there is no reject
}

Step 4)Process "Manager approval" and set its taskcreating event:

Private void managertaskcreating (Object sender, quickflow. taskeventargs E)
{
E. taskproperties. assignedto = "DC \ manager ";
}

Done!

 

About grouptask

Every time you use mulititask, you must writeCodeIt is a bad habit to designate an approver. Generally, the approver can follow certain rules, such as from a Sharepoint group, an ad group, or a third-party role management system, obviously, we should encapsulate these common user acquisition logic.

Grouptask inherits from multitask, and its code is very simple. It just extracts the user from a group in the initialized event of multitask and adds it to the users set. In this way, if you want to assign a task to a user in the SharePoint user group, you can directly use grouptask to set its group attribute:

// Grouptask

Void grouptask_initialized (Object sender, eventargs E)
{

If (this. workflowproperties = NULL)
Throw new exception ("workflowproperties is null, Please bind it to correct field ");

Sproleuserprovider up = new sproleuserprovider ();

Ilist <user> Users = NULL;
Try
{
If (this. deptinherits)
{
User user = up. getuser (this. workflowproperties. Web, this. workflowproperties. originator );
Users = up. getroleusers (this. workflowproperties. Web, this. Group, user. Department );
}
Else
{
Users = up. getroleusers (this. workflowproperties. Web, this. group );
}
}
Catch (exception ex)
{
Activityutil. Log (this, spworkflowhistoryeventtype. workflowerror, null, "error retrieving group users [" + this. Group + "]", Ex. Message );
Throw ex;
}

Foreach (User U in users)
{
This. Users. Add (U. loginname );
}
}

Grouptask has a deptinherit attribute. What is this?

Assume that one step of approval is "department manager approval", and this company is a large company with multiple departments, each submitted by the people to initiate the approval, they all need to be approved by the "manager of his department". How can this problem be achieved?
One way is to use the department manager as the user's ad attribute for maintenance in the ad, you only need to use the task activity and write code to get it from the user's ad attribute, one disadvantage of this approach is that the maintenance workload is too large.

There is also a simple way: to create a department manager group on the website, each user in the indexing poing has a "department" attribute, the attributes of the submitter and the "department manager" must be the same. Then, use the submitter's department attributes to filter the attributes of the department manager from the department manager group, and you can get the "department manager ", when deptinerit is set to true, grouptask performs this operation. Of course, this method requires that the "department" attribute of users in ad must be correctly maintained and synchronized to USERPROFILE correctly (one hour after maintenance in AD ).

These two methods do not require the development of a dedicated "User role management system". If you have a sound role management system, it may be more "beautiful.

If you have used K2, you can compare the multitask and grouptask with the clientevent of K2.

Download sample code:

Http://files.cnblogs.com/jianyi0115/QuickFlowExample_%E4%BC%9A%E7%AD%BE.zip

Note: This code has not been tested and can only be used as a reference.

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.