Hi,
My workflow is not being triggered after an item is added to my list. I have tried debugging and it appears the workflowguid which I obtain from the SharePoint designer list workflow does not match the association baseid at any time. I am not
quite sure why this happens. This is a sample of my code below. Any help would be gladly appreciated. I have already looked at the other articles and I was not able to solve my problem. What I am trying to accomplish is to simple trigger
a SharePoint designer workflow programmatically through an even receiver list item added. But this never appears to be true: if (association.BaseId == workflowGuid)
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
startWF(properties);
}
private void startWF(SPItemEventProperties properties)
{
try
{
//bool startWF = false;
string strWorkflowID = "c66ff94f-ba7c-4495-82fe-e73cdd18bad9";
//string statusVal = properties.AfterProperties["eRequest Division"].ToString();
SPListItem li = properties.ListItem;
using (SPWeb web = li.Web)
{
using (SPSite site = web.Site)
{
SPWorkflowManager mgr = site.WorkflowManager;
SPList parentList = li.ParentList;
SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
LookUpAndStart(li, mgr, associationCollection, "c66ff94f-ba7c-4495-82fe-e73cdd18bad9");
}
}
}
catch (Exception ex)
{
}
}
private static void LookUpAndStart(SPListItem listItem, SPWorkflowManager mgr, SPWorkflowAssociationCollection associationCollection, string workflowID)
{
foreach (SPWorkflowAssociation association in associationCollection)
{
Guid workflowGuid = new Guid(workflowID);
//if (association.Name.ToLower().Equals(workflowGuid))
//if (association.BaseId == workflowGuid)
//if (association.BaseId.ToString("B").Equals(workflowGuid))
if (association.BaseId == workflowGuid)
{
string data = association.AssociationData;
SPWorkflow wf = mgr.StartWorkflow(listItem, association, data, true);
break;
}
}
}
}
}