Showing posts with label Tasks. Show all posts
Showing posts with label Tasks. Show all posts

Tuesday, July 17, 2012

Get value from custom fields in workflow task


 To get value from specific field of an item, you need to know the guid of that field. Following is a way to get value from custom workflow task field.



Ex.

Guid testStatusFieldId = workflowProperties.TaskList.Fields["Test Status"].Id;
var status = (string)(Q0AfterProperty.ExtendedProperties[testStatusFieldId]);
if (status == "Q1")
{
                _isQ1 = true;
}
else if (status == "Q4")
{
                _isQ4 = true;
}

Monday, July 9, 2012

Delete all related tasks when workflow complete in sharepoint

When your workflow finished or terminated, you might see some tasks still remain in the task list. Do you want to get rid of them?

Following code help you to remove all tasks remain after workflow complete.


using (var spweb = workflowProperties.Web)
                {
                    spweb.AllowUnsafeUpdates = true;
                    var list = workflowProperties.Item.Tasks.Count;
                    while (list>0)
                    {
                        workflowProperties.Item.Tasks[0].Delete();
                        list = workflowProperties.Item.Tasks.Count;
                    }
                    spweb.AllowUnsafeUpdates = false;
                }