1

I have created a custom web part that insert an item into a list. I deployed this web part to production and all seems to be working well.

I now created a workflow on this list in Designer. Once a record gets inserted I need an email to be sent. I'm testing and this is what happens:

  1. Via the web part an item in the list is created and the workflow does not seem to be triggered.

  2. I insert a new item in the list using the UI by clicking on "Add a new item" and the workflow is triggered.

Is there any way to get the workflow to work when new item is created by the web part? Should it matter how the item gets created as long as a new item is created in the list?

Thanks, Ninel

2 Answers 2

2

Here's the solution that worked for me:

SPList taskList = Web.Lists["Workflow Tasks"];

SPList historieList = Web.Lists["Workflow History"];

SPWorkflowAssociation myAssociation = list.WorkflowAssociations.GetAssociationByName("Your Workflow Name", System.Threading.Thread.CurrentThread.CurrentCulture);

myAssociation.AllowManual = true;

myAssociation.AutoStartChange = true;

myAssociation.AutoStartCreate = true;

myAssociation.AssociationData = string.Empty;

list.Update();

site.WorkflowManager.StartWorkflow(item, myAssociation, myAssociation.AssociationData);

1
0

If you have attached the workflow to the list you are adding to then the workflow should trigger automatically, unless you have specified the workflow NOT to trigger automatically.

If you are using custom code you have deployed from Visual Studio you will need to start the workflow programmatically.

try this site - How to start workflow programmatically

S

2
  • Yes, I deployed a wsp that inserts the item into the list. Would you happen to know any good sites that explain how to start the workflow programmatically?
    – ninel
    Commented Mar 18, 2013 at 17:19
  • Updated my answer
    – Stephen
    Commented Mar 18, 2013 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.