1)需求概述
在工作流列表中添加一个视图,显示当前用户审批过(参与过)的流程/单据
2)解决方案
增加一个多用户类型的栏WorkflowApprovers到列表,在流程的运行过程中,把所有任务的参与人增加到这个栏中,然后创建一个视图,用WorkflowApprovers过滤即可。
显然这是一个通用的功能,及任何流程的任何任务都需要这个处理逻辑, 在QuickFlow中,处理通用的流程逻辑可以通过实现WorkflowEventReceiver实现,
注意:这个WorkflowEventReceiver是QuickFlow的WorkflowEventReceiver,而不是MOSS内部的。
关于WorkflowEventReceiver,可以参考这篇文章:http://www.cnblogs.com/jianyi0115/archive/2009/09/15/1567324.html
3)WorkflowEventReceiver的实现
创建一个强签名类库,引用QuickFlow.dll,添加一个类,代码如下:
public class ApproversWorkflowEventReceiver : QuickFlow.EventBus.WorkflowEventReceiver { const string Field_Name = "WorkflowApprovers"; const string Field_Xml = @"<Field Type='UserMulti' DisplayName='WorkflowApprovers' List='UserInfo' Required='FALSE' ShowField='ImnName' UserSelectionMode='PeopleOnly' UserSelectionScope='0' Mult='TRUE' Sortable='FALSE' StaticName='WorkflowApprovers' Name='WorkflowApprovers' />"; public override void OnTaskCompleted(QuickFlow.EventBus.WorkflowEventProperties p) { var taskUserAccount = p.TaskProperties.AssignedTo; if (String.IsNullOrEmpty(taskUserAccount)) return; if (p.WorkflowProperties.List.Fields.ContainsField(Field_Name) == false) { //throw new Exception("workflow list must have a multi-user field named Approvers"); p.WorkflowProperties.List.Fields.AddFieldAsXml(Field_Xml); } var approvalUser = p.WorkflowProperties.Web.EnsureUser(taskUserAccount); //approvalUser = p.TaskProperties.ExtendedProperties[WorkflowConstants.TaskUserIdentityPropertyName] SPFieldUserValueCollection users = p.WorkflowProperties.Item[Field_Name] as SPFieldUserValueCollection; if (users == null) { users = new SPFieldUserValueCollection(); } else { foreach (SPFieldUserValue u in users)//用户已经存在,无需增加 { if (approvalUser.ID == u.LookupId) return; } } users.Add(new SPFieldUserValue(p.WorkflowProperties.Web, approvalUser.ID, approvalUser.Name)); var root = ActivityUtil.GetRootActivity(p.Activity) as FlowchartWorkflow; if (root != null) { root.DataFields[Field_Name] = users; root.DataFields.Update();//强制更新 } } }
完整的示例代码 下载
4)配置
step1:将类库部署到GAC,修改global.config,增加Event配置:
<GlobalConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <EventReceivers> <Receiver Enabled="true" Name="ApproversWorkflowEventReceiver" Type="ProjectName1.ApproversWorkflowEventReceiver,ProjectName1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec1e0fe6e1745628" /> </EventReceivers> </GlobalConfiguration>
step2:在列表中增加一个多选用户类型字段WorkflowApprovers。添加字段后,可以按照需要把WorkflowApprovers改为其他显示名
step3:创建一个视图-我审批过的单据,设置过滤条件为 WorkflowApprovers = [本人]
5)后记
最新版本QuickFlow(Build120325之后版本)已经集成了ApproversWorkflowEventReceiver,无需自己开发WorkflowEventReceiver,直接修改global.config即可:
<EventReceivers> <Receiver Enabled="true" Name="ApproversWorkflowEventReceiver" Type="QuickFlow.EventBus.ApproversWorkflowEventReceiver,QuickFlow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec1e0fe6e1745628" /> </EventReceivers>