会签是指联合审批,当一个任务需要多人同时审批时,我们就会用动会签,他能根据条件来实现审批:当全部同意时通、当有一个同意时通过等等情况。
多人同时任务事先是不确定人数的,这里我们用到replicator Activity来复制任务,以我们要求来创建多个任务,同时发出给多人审批。
老规矩,先来新建一个工作流,拖入replicator,再在replicator 中放一个TaskActivity。
其中replicatorActivity1设置如图,taskActivity1不动,什么属性都不设置
Initialized事件是最先运行,初始化,我们在这里增加代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | private void replicatorActivity1_Initialized(object sender, EventArgs e) { SPWeb web = this.workflowProperties.Web; SPListItem item = this.workflowProperties.Item; SPFieldUser uField = item.Fields["canomo"] as SPFieldUser; if (uField.AllowMultipleValues) //允许多重选择 { SPFieldUserValueCollection userValues = item["canomo"] as SPFieldUserValueCollection; foreach (SPFieldUserValue userValue in userValues) { if (null != userValue.User) { this.replicatorActivity1.CurrentChildData.Add(userValue.User.LoginName); } } } } |
ChildInitialized事件用来创建多人任务
1 2 3 4 5 6 7 8 | private void replicatorActivity1_ChildInitialized(object sender, ReplicatorChildEventArgs e) { TaskActivity activity = e.Activity as TaskActivity; activity.TaskProperties = new SPWorkflowTaskProperties(); activity.TaskProperties.AssignedTo = e.InstanceData.ToString(); activity.TaskProperties.Title = "会签审批任务"; } |
ChildCompleted事件,有一个任务完成就执行
1 2 3 4 5 6 | private List<SPWorkflowTaskProperties> taskPropertiesList = new List<SPWorkflowTaskProperties>(); private void replicatorActivity1_ChildCompleted(object sender, ReplicatorChildEventArgs e) { TaskActivity activity = e.Activity as TaskActivity; taskPropertiesList.Add(activity.TaskProperties); } |
UntilCondition设置为代码条件
1 2 3 4 5 6 7 8 9 10 11 12 | private void Until(object sender, ConditionalEventArgs e) { foreach (SPWorkflowTaskProperties taskProp in this.taskPropertiesList) { if (taskProp.Description != "ok") { e.Result = true; return; } } e.Result = this.taskPropertiesList.Count == this.replicatorActivity1.CurrentChildData.Count; } |