第一个要分享的是获取当前的申请状态以及当前的处理人,虽然我们很容易通过BPMInstProcSteps这张表找到FinishAt is Null的记录,但是如果直接用2表的关联查询会有并行流程的问题,另外当你把自己的申请数据独立开来,做跨数据的关联就有些不直观,索性写一个函数GetBPMCurrentStep(@TaskID),使用方法很简单,直接在自己的视图里面使用就行。
USE [WAIWorkflow] GO /****** Object: UserDefinedFunction [dbo].[GetBPMCurrentStep] Script Date: 05/24/2011 14:34:50 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[GetBPMCurrentStep](@TaskID nvarchar(50)) RETURNS nvarchar(Max) AS BEGIN DECLARE @r nvarchar(Max) SET @r = '' SELECT @r = @r + ',' + NodeName + '('+ OwnerAccount+')' FROM [BPMDB].[dbo].[BPMInstProcSteps] WHERE TaskID=@TaskID AND [FinishAt] is null RETURN STUFF(@r, 1, 1, '') END
第二个要分享的就是每个申请的摘要信息(下图),这个信息根据用户的需要可能需要增加一些字段或者删除一些字段,但是当更改以后,只对新的申请有效。老的申请只能通过自己写Sql后台运行,其实也不难,把自己的所有申请用到的表列出来,每个流程写一段语句,批量执行就行了。
--更新 NPD 的Task Description update [BPMDB].[dbo].BPMInstTaskssetDescription = b.WAI_PN + ',' + b.Lester_Number from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormNPD b where a.TaskID=b.TaskID --更新 FormADandEmail 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormADandEmail b where a.TaskID=b.TaskID --更新 FormBaanSession 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormBaanSession b where a.TaskID=b.TaskID --更新 FormComputer 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormComputer b wherea.TaskID=b.TaskID --更新 FormEmployeeOnBoard 的Task Description update [BPMDB].[dbo].BPMInstTasksset Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormEmployeeOnBoard b where a.TaskID=b.TaskID --更新 FormEmployeeResignation 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormEmployeeResignation b where a.TaskID=b.TaskID --更新 FormSeat 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormSeat b where a.TaskID=b.TaskID --更新 FormShortNumber 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName+ ',' + b.Mobile from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormShortNumber b where a.TaskID=b.TaskID --更新 FormTelephone 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormTelephone b wherea.TaskID=b.TaskID --更新 FormVPN 的Task Descriptionupdate [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormVPN b where a.TaskID=b.TaskID --更新 FormWirelessCard 的Task Description update [BPMDB].[dbo].BPMInstTasks set Description = b.EmployeeID + ',' + b.ChineseName + ',' + b.EnglishName from [BPMDB].[dbo].BPMInstTasks a, [WAIWorkflow].[dbo].FormWirelessCard b where a.TaskID=b.TaskID
受用,强的很!
后来发现如果b.EmployeeID,b.ChineseName或b.EnglishName中有Null值,更新的结果也是Null值,也许是使用+号的缘故,解决方法就是:替换b.ChineseName为(case when b.ChineseName is null then ” else b.ChineseName end),其它的按照此方法依葫芦画瓢。