How to cancel inprogress workflow?
SPWorkflowCollection itemWorkflowCollection= listItem.Workflows;
foreach (SPWorkflow itemWorkflow in itemWorkflowCollection)
{
//cycle workflows associated to the item (listItem)
if (!itemWorkflow.IsCompleted && itemWorkflow.InternalState == SPWorkflowState.Running)
{
foreach (SPWorkflowTask taskWorkflow in itemWorkflow.Tasks)
{
//cycle throught all tasks associated to the workflow
//if task is not completed
if (taskWorkflow["PercentComplete"].ToString() != "1")
{
//you can cancel or change the running tasks before canceling the workflow
taskWorkflow["Status"] = "Canceled";
taskWorkflow["PercentComplete"] = 1;
web.AllowUnsafeUpdates = true;
taskWorkflow.Update();
}
}
SPWorkflowManager.CancelWorkflow(itemWorkflow);
}
}
Enjoi...
Showing posts with label MOSS 2007 Workflows. Show all posts
Showing posts with label MOSS 2007 Workflows. Show all posts
Friday, March 2, 2012
Wednesday, April 7, 2010
Workflow - Failed on Start error.
I have a practice of changing the default class name of workflow1.cs to some logical name.cs based on the workflow i create. I created the workflow deployed it - however when I run the workflow - i get "Failed on start".
I even tried to debug the same but breakpoint never came.
I made a silly mistake in workflow.xml.I forgot to change the class name
CodeBesideClass="Namespace.Workflow1"
Resolution: Just change the Workflow1.cs to your classname and done....;))
CodeBesideClass="Namespace.CustomWorkflowClassName"
I even tried to debug the same but breakpoint never came.
I made a silly mistake in workflow.xml.I forgot to change the class name
CodeBesideClass="Namespace.Workflow1"
Resolution: Just change the Workflow1.cs to your classname and done....;))
CodeBesideClass="Namespace.CustomWorkflowClassName"
Subscribe to:
Posts (Atom)