I have a list with one content type "Leave Request".
I built a workflow for this CT and added to the list.
When add an item the workflow run but when add the item programmaticlly then the workflow doesn't fire.
here is the sample:
SPContentType itemtype = list.ContentTypes["Leave Request"];
SPListItem newItem = list.Items.Add();
newItem["Title"] = web.CurrentUser.Name + "test man";
newItem["ContentTypeId"] = itemtype.Id;
newItem.Update();
also tried this function too, but no result.
public static void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName)
{
SPList parentList = listItem.ParentList;
SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
//return zero as count because no WF is associated with this list. also used SPContentType itemtype and itemtype.WorkflowAssociations but no luck.
foreach (SPWorkflowAssociation association in associationCollection)
{
if (association.Name == wfName)
{
association.AutoStartChange = true;
association.AutoStartCreate = false;
association.AssociationData = string.Empty;
spSite.WorkflowManager.StartWorkflow(listItem, association, association.AssociationData);
}
}
}
It seems when I add by C# i'm adding to list not content type although I'm specifying content type.
can you please help me on this?