locked
InvokeWorkflowActivity to invoke another workflow RRS feed

  • Question

  • From my custom SharePoint workflow I want to invoke another workflow and for this I am using the InvokeWorkflowActivity.  Unfortunately the host workflow completes but the second workflow does not even start.  Is the InvokeWorkflowActivity supported in SharePoint in the first place?
    Wednesday, October 5, 2011 9:49 AM

Answers

  • so just to be clear, you want to call another workflow programmatically from the initial workflow?

    if this is what you're trying to do, as luck would have it i wrote a blog post about just that exact functionality:

    http://blogs.msdn.com/b/sharepointdev/archive/2011/08/23/calling-sharepoint-workflow-instances-programmatically-from-other-sharepoint-workflows.aspx

    :)

    the cliff notes are that you will need to first find the workflow's association template on the list, then instantiate a new workflow manager and start the workflow.

    Guid svpwfid = new Guid("4e126fc9-6b12-1212-8c21-21120f264bad");
    var wfa = (from SPWorkflowAssociation spwfa in workflowProperties.Item.ParentList.WorkflowAssociations
               where spwfa.BaseId == svpwfid && spwfa.Enabled == true
               select spwfa).FirstOrDefault();
    
    if (wfa != null)
    {
        SPWorkflowManager wfMan = workflowProperties.Item.ParentList.ParentWeb.Site.WorkflowManager;
        wfMan.StartWorkflow(workflowProperties.Item, wfa, wfa.AssociationData, true);
    }
    else
    {
        // could not find workflow template.
    }
    



    Justin Joyce SharePoint Solution Architect http://lantekcs.com
    • Marked as answer by Shimin Huang Friday, October 14, 2011 7:27 AM
    Wednesday, October 5, 2011 6:58 PM

All replies

  • so just to be clear, you want to call another workflow programmatically from the initial workflow?

    if this is what you're trying to do, as luck would have it i wrote a blog post about just that exact functionality:

    http://blogs.msdn.com/b/sharepointdev/archive/2011/08/23/calling-sharepoint-workflow-instances-programmatically-from-other-sharepoint-workflows.aspx

    :)

    the cliff notes are that you will need to first find the workflow's association template on the list, then instantiate a new workflow manager and start the workflow.

    Guid svpwfid = new Guid("4e126fc9-6b12-1212-8c21-21120f264bad");
    var wfa = (from SPWorkflowAssociation spwfa in workflowProperties.Item.ParentList.WorkflowAssociations
               where spwfa.BaseId == svpwfid && spwfa.Enabled == true
               select spwfa).FirstOrDefault();
    
    if (wfa != null)
    {
        SPWorkflowManager wfMan = workflowProperties.Item.ParentList.ParentWeb.Site.WorkflowManager;
        wfMan.StartWorkflow(workflowProperties.Item, wfa, wfa.AssociationData, true);
    }
    else
    {
        // could not find workflow template.
    }
    



    Justin Joyce SharePoint Solution Architect http://lantekcs.com
    • Marked as answer by Shimin Huang Friday, October 14, 2011 7:27 AM
    Wednesday, October 5, 2011 6:58 PM
  • Actually I am specifically referring to the InvokeWorkflowActivity not doing it programatically.
    Thursday, October 6, 2011 2:51 AM