I have created a custom action for starting the workflow on list item. When user selects the item, an item from ribbon is enabled to start the workflow directly on item.
I have created on application page to make redirection to the workflow initiation form. But my problem is that I want to first determine that if the workflow is possible on the current selected item or not. i.e. SharePoint does not allow to start the workflow if the current workflow status is Error Occurred
and etc.
I have found this link which describes the list of enumeration of status of workflow running on list item.
Among the list which values should I compare to allow the user to start workflow. If the workflow is not able to start on the item I would display the alert box to user.
My code is:
private void RedirectToInitiationForm(string itemId, string listId,string sourceUrl)
{
try
{
// getting current web from context.
SPWeb currentWeb = SPContext.Current.Web;
SPList Documents = currentWeb.Lists[new Guid(listId)];
SPWorkflowAssociation wfAssociation = qmsDocuments.WorkflowAssociations.Cast<SPWorkflowAssociation>().FirstOrDefault(wa => wa.BaseId == Constants.WorkflowAssociationID);
if (wfAssociation != null)
{
// getting item GUID
SPListItem DocItem = Documents.GetItemById(Convert.ToInt32(itemId));
string url = SPUrlUtility.CombineUrl(currentWeb.Url,"/"+ wfAssociation.InstantiationUrl +"?List="+ new Guid(listId).ToString("B")+"&ID="+ itemId +"&ItemGuid="+ qmsDocItem.UniqueId.ToString("B")+"&TemplateID="+ wfAssociation.Id.ToString("B")+"&source="+ sourceUrl);
Response.Redirect(url);
}
}
catch (Exception ex)
{
}
finally
{
}
}
Which are the statuses of the workflow should I consider to allow user to enable workflow? I will check the status of workflow prior to Response.Redirect()
statement. But I don't which status should I consider for allowing user to start workflow and which status will not allow user to start workflow.
Please help.