Wednesday, July 15, 2009, 12:14
Posted by Administrator
A small tip while using the OntaskChanged activity, if you want to check if the assigned has completed his task don't use the AfterProperties.PercentComplete property .Posted by Administrator
Problematic situation:
A user modifies the task and the OntaskChanged_Invoked eventhandler is triggered. In this eventhandler the system checks is the user completed the task by setting the PercentCompleted formfield.
When the user doesn't uses the PercentCompleted field, but he uses the Status field. The workflow will crash because the code that is written behind the PercentComplete property of the AfterProperties object uses the StringToNumber(...) method.
//This will crash if the user leaves percentcomplete empty string perComp = AfterProperties.PercentComplete;
Solution
AfterProperties contains a hashtable called ExtendedProperties, this hashtable has a guid as key(these guids can be found here ) and the current value as a string.By using this hashtable the system can first check if the Guid is available and if the stringvalue is valid.
//Get the percentcompleted value of the task by using the hashtable
string perComp = AfterProperties.ExtendedProperties(Microsoft.SharePoint.SPbuiltInFieldId.PercentComplete);
if(String.IsNullOrEmpty(perComp)){
...
You should also check if the user didn't use the status combobox to set his task as completed.
//Get the status value of the task by using the hashtable
string status= AfterProperties.ExtendedProperties(Microsoft.SharePoint.SPbuiltInFieldId.TaskStatus);
if(status == "Completed"){
...




( 2.9 / 553 )

Tom Van Gaever - Blog



Avatar






