I have a service that automatically uploads documents to a SharePoint 2013 Document Library. I created a simple workflow that starts when a new item is created and just sends an email notification; however, the workflow only starts when I manually add a document and not when it's uploaded by the service. Thank you in advance for any ideas on how to resolve it.
Asked
Active
Viewed 3,419 times
2 Answers
0
If you have attached your workflow to the list, the workflow should be triggered automatically. I found some case like this before. please check [here][1]

Community
- 1
- 1

febriyana.sudrajat
- 66
- 1
- 6
-
The workflow only triggers when I upload a file through UI, not when it's uploaded automatically (using System Account). The line 'site.WorkflowManager.StartWorkflow(item, myAssociation, myAssociation.AssociationData);' asks for **item** (SharePoint entity) which I don't have a way to specify in the code. – Kate Jan 02 '14 at 18:50
0
I had to add some code to start a workflow after the app does its stuff:
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
static void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName)
{
SPList parentList = listItem.ParentList;
SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
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);
}
}
}

Kate
- 1,495
- 4
- 21
- 35