Below is some sample code to provision a workflow on the host web from your app web. This sample code is in one block for demo purposes. It makes 4 asynchronous calls to SharePoint to complete successfully.

In the event you’d want to define in your App a workflow that would run on a list in the host web this is the code you would use to deploy (move it from App to Host) and attach it to a list in the host web.

NOTE: you must include a reference to “/_layouts/15/SP.WorkflowServices.js”

Comments
  • cv
    Posted at 5:29 pm October 7, 2015
    cv
    Reply
    Author

    Nice Article, Thanks for sharing.
    I want to know is it possible to deploy custom workflow activities from App web to hostweb?

    Thank you

    • Spyros
      Posted at 5:32 pm January 17, 2016
      Spyros
      Reply
      Author

      Hi cv,

      Did you ever figure this out? It seems that if your workflows contain custom activities, you get an error trying to deploy the workflows from app web to host web. Do you know if there is a way of programmatically deploy the actvities to host web?

      Thanks

  • Soyeb Malek
    Posted at 6:33 am September 24, 2015
    Soyeb Malek
    Reply
    Author

    Great Job Thomas..
    Perfect Code.. Thanks for sharing..

  • Mike
    Posted at 1:24 pm March 3, 2015
    Mike
    Reply
    Author

    I trying your code and it’s creating the workflow and association but not carrying over the initiation form. Is there something that needs to be set on the subscription object or elsewhere to set the workflow to first call the init form?

  • Shangar
    Posted at 10:49 pm December 8, 2014
    Shangar
    Reply
    Author

    Hi,

    How to implement this to SharePoint-Host Apps? Event Handler is not support to SharePoint-Hosted Apps.

    Thank you.

    • Thomas Daly
      Posted at 8:30 pm January 3, 2015
      Thomas Daly
      Reply
      Author

      This article is based on SharePoint hosted apps. To provision to the SharePoint site you would need to implement a configuration screen in your app.

      • Sri
        Posted at 1:00 pm February 27, 2015
        Sri
        Reply
        Author

        Hi Thomas,
        Can I use above code to associate workflow from app web to host web on ONPREMISES SharePoint 2013. Seems everyone are talking about associating on SharePoint online only. Is there a way to associate a app workflow to already created host web in SharePoint ONPREMISES.

        Thank you

  • Dedek
    Posted at 7:26 am June 16, 2014
    Dedek
    Reply
    Author

    Good job, this is awesome piece of code! Very useful, thanks for sharing.

  • Leave a Reply