How (not) to complete workflow tasks using code in WSS3

How (not) to complete workflow tasks using code in WSS3

Developing workflows for Windows SharePoint Services 3 can sometimes be somewhat of a black art. Using ASP.NET provides you with the tools to create customized interfaces, but the exact steps required must be found in other sources. One of the issues I find in some of the content I read on the web relates to the way tasks work in SharePoint and how you can complete them correctly.

There are various ways a user receives feedback on the status of a task. You can set a Status field to Complete, or set the Percent Completed to 100%. A task created by a workflow also has a task outcome field to store custom information regarding the task's completion or failure.

Now first of all, both have little to do with the actual completion of a task as far as SharePoint is concerned. It is for instance possible to have a task status set to Completed while the Percent Completed isn't 100%:

Furthermore, a task can also not be set to 'Completed' in a reliable fashion. Users are allowed to change the possible values of the Status column.

The correct way of completing tasks using code is to use the built-in Completed field, which is hidden from the user and hence provides the right way of completing tasks. You can also get the right localized text for the status column, as long as the values haven't been changed by the user. The SPBuiltInFieldId class provides the right values for columns in the task list. You can use the SPResource class to get the localized text representing the 'Complete' text using the WorkflowTaskStatusComplete resource.

 Hashtable data = new Hashtable(); data[SPBuiltInFieldId.Completed] = "TRUE"; data[SPBuiltInFieldId.PercentComplete] = 1; data[SPBuiltInFieldId.TaskStatus] = SPResource.GetString( new CultureInfo( (int)taskListItem.Web.Language, false), "WorkflowTaskStatusComplete", new object[0]);

Hope it helps!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值