Saturday 13 September 2014

Deploy Workflows to Host Web with Integrated Workflow Apps

Update (19/08/2015): Integrated Workflow Apps are now part of Visual Studio 2015. You do not need to manually edit any XML files now. You will just need to:

1) Use Visual Studio 2015 (I was using the Enterprise version)

2) Create a SharePoint App (Add-In as it's now called)

3) Add a Workflow to your Add-In Project. (Your Add-In cannot be an Integrated Workflow Add-In unless there is a Workflow in it)

4) Go to the Project Properties and set the "Integrated App" property to True. That's it!



Original Article:

In the recent Office 365 Developer YamJam on the Office 365 Technical Network, there were lots of great questions asked to and answered by the Office 365 Engineering Team. You can view all the questions over here: https://www.yammer.com/itpronetwork/#/threads/inGroup?type=in_group&feedId=4419638

One thing which I was interested in was the Integrated Workflow Apps. I have seen a lot of people ask about this as they want to deploy Workflows to their Host Web (or Content Site) from their Apps. I had known that something was in the pipeline as I had seen a glimpse of it in this video from SPC 2014 http://channel9.msdn.com/Events/SharePoint-Conference/2014/SPC3994 

Luckily, Tim McConnell who is the speaker in the video was part of the YamJam and he answered that Integrated Workflow Apps are already available on SharePoint Online but they are waiting for tooling support so no official announcement has been made till now.

I have tested them on my development Office 365 Tenant and it works! In this post, I will be detailing the process by which you can get it working too. 

You will need to have installed Visual Studio 2013 and Microsoft Office Developer Tools for Visual Studio 2013 for this. My test project is available on GitHub here: https://github.com/vman/Integrated-Workflow-Apps

1) Start Visual Studio 2013 > New Project > App for SharePoint



2) Enter the SharePoint Online Site Url and select the hosting model for your app. I have selected SharePoint Hosted.



3) Right Click App Project > Add > New Item



 4) Select Workflow and type in a name for your Workflow

(Click on the Image to Zoom)

5) Select the type of Workflow as Site Workflow


(List Workflow Deployment is shown at the end of the post) 



6) Select "Create New" for History List and Task List.




7) Add some sample activities to your Workflow.


I have added a LookupWorkflowContextProperty to get the current Site Url and a WriteToHistory activity which will write the Current Site Url to the History List

(Click on the Image to Zoom)

(Click on the Image to Zoom)

8) Give your App Manage Permissions on the Web:



9) Right click App Project > Publish > Package the app. A window will pop up showing you the packaged .app file.

(Click on the Image to Zoom)

10) Now the interesting part. Open the .app file as an archive with a tool of your choice.


 I have used 7-Zip which is a really awesome tool. You can download it from here: http://www.7-zip.org/

(Click on the Image to Zoom)

11) Once opened, look for the WorkflowManifest.xml file and open it. It will be empty to start with. Copy the following in the file and save it.



(Click on the Image to Zoom)

12) After Clicking save, you will get the following prompt. Click Ok. 



13) Now your .app package is ready to be deployed to your App Catalog. Go to your App Catalog and upload the .app file in the "Apps for SharePoint" document library. 



14) Once uploaded, go to your Team Site > Site Contents > Add an App > Select your app and add it to your Team Site.




15) You will be prompted to trust your App. Click on "Trust It".



16) Once the App is installed on your site, go to Site Contents > Site Workflows



17) Click on your App to see your Site Workflow deployed on the site. Click on the Workflow to start it. 

(Click on the Image to Zoom)

18) Let the workflow complete. After it has completed, click on the Internal Status to see what the workflow logged to the History List 

(Click on the Image to Zoom)

19) You can see that the Workflow logged the url of the Team Site on which it was running. 

(Click on the Image to Zoom)

This proves that the Workflow was deployed to and ran on the Host Web (Content Site).

Deploy List Workflow:


The process to deploy the list workflow is quite the same except in step 5, select List Workflow.  



Do not associate your workflow to any List. We will do the association after the deployment of the Workflow.



Select when you want your workflow to start. 



Add a Sample Workflow Activity in the Workflow to Log the Current List Name and the Current Item Url:



Steps 8 to 15 are the same as for a Site Workflow. After the Workflow is deployed, Go to a list > List Settings > Workflow Settings > Add a Workflow



Click on your App, Associate your Custom Workflow by giving it a name and configuring other settings. Click on OK.  



After you associate the Workflow, Start it either manually, or create an item, or update an item depending on the method you selected in the Workflow Designer in the App. 



After the Workflow Completes, Click on the Internal Status to see what the Workflow Logged to the History List:



Thanks for reading!

38 comments:

Sri said...

Hi Vardhaman,

I followed the steps you mentioned, but I don't see my app on the add a workflow page for a list. I'm using VS 2012, is that a problem?

Vardhaman Deshpande said...

Hi Sri,

Sorry I haven't tested the process in VS 2012. Maybe you can try to see where your project differs from mine. My project is on github and I have posted the link int he article.

Unknown said...

Hi Sri,

Are you testing against SharePoint Online or a SharePoint 2013 server? As Vardhaman mentioned, integrated workflows are not available in the server product.

Thanks,
-Tim [MSFT]

Munnu said...

Hi ,

I have followed same steps i was getting the following error.

The server at apps-b99ebeeafe35a7.solutionapps.com.dns can't be found, because the DNS lookup failed. DNS is the network service that translates a website's name to its Internet address. This error is most often caused by having no connection to the Internet or a misconfigured network. It can also be caused by an unresponsive DNS server or a firewall preventing Google Chrome from accessing the network.


Please help me to resolve it as soon as possible. Very Urgent for me.

Thank you

Vardhaman Deshpande said...

Are you on On-Premises SharePoint? This only works with SharePoint Online

Munnu said...

Hi ,

Iam working on-Premise.

I need to work for On-Premise.

Is there a way to get it working. Please guide me.

Can u please explain me why it works only for SPOnline.

Thank you in advance.

Vardhaman Deshpande said...

As Tim McConnell (from the SharePoint product group) said above, they have not yet made this functionality available in On-Premises SharePoint Server Product. It might be there as part of future versions or service packs.

Munnu said...

Thank you!

Unknown said...

Hi Vardhaman.

I have followed your steps and the site workflow is working... But when I try to add a list workflow I get the following error

"Sorry, you don't have access to this page
Awaiting approval. We'll let you know about any updates."

Do you have any idea ??

Martin

Unknown said...

Sorry... Just figured it out.... I forgot to set the permission on the list workflow in the app

Thx
Martin

Vardhaman Deshpande said...

Hi Martin,

Most likely it is a permissions issue. I did face the same error but giving the App Manage permissions on the Host Web fixed it for me.

You can try giving different permissions in the App Manifest.

Unknown said...

Hi... Thanks for all your help... but so far I have not been able to get the status working with different permissions... I suspect that this issue is related to my other problem... I can't get the list workflow to start on item created or updated... It Works when I start it manually… I have also noted that I don’t get the option to select “manually”, “Item created” or “Item changed” as showed on image 18 in your tutorial. I’m not sure if this has to do with my VS version or that I’m trying this on at Sharepoint site that’s not a developer site…..

Regards
Martin

Vardhaman Deshpande said...

Have you installed all the updates to Visual Studio 2013? And do you also have the latest version of Microsoft Office Developer Tools for Visual Studio 2013?

Unknown said...

Hi... I'm running VS 2013 Update 4 and office tools via Web platform installer... November 2014 update

Martin

Zeba said...

Hi Vardhaman, I followed your steps and I was able to deploy the app and the workflow seems to be working. I am using VS 2012 with O365 tools.

After following ur steps I am trying to execute a workflow which will be associated to Discussion list on HostSite.

I followed the same steps for apps but I changed the workflow with below steps:
1. LookupSPListItem : (ItemId and ListItem = currentitem, dynamic value = dv_0)
2. GetDynamicValueProperties : (Source = dv_0, Properties:- Entity Type= ListItem, Path= IsQuestion, AssignTo =Question(variable dynamic))
3. Build collection string: (values = Question.Tostring(), result=locquestion(string variable))
4. Write to history: (message= "Question values is:" + locQuestion)

Also performed app permission: web= manage and added the xml in WFManifest file

I deployed it on app store, but when I add the app it says "Sorry, something went wrong with adding the app."

I am not sure what I am doing wrong. Can you please guide me in this scenario?

Zeba said...

Hi Vardhaman, I followed your steps and I was able to deploy the app and the workflow seems to be working fine. I am using VS 2012 with O365 tools.

After following ur steps I am trying to execute a workflow which will be associated to Discussion list on HostSite.

I followed the same steps for apps but I changed the workflow with below steps:
1. LookupSPListItem : (ItemId and ListItem = currentitem, dynamic value = dv_0)
2. GetDynamicValueProperties : (Source = dv_0, Properties:- Entity Type= ListItem, Path= IsQuestion, AssignTo =Question(variable dynamic))
3. Build collection string: (values = Question.Tostring(), result=locquestion(string variable))
4. Write to history: (message= "Question values is:" + locQuestion)

Also performed app permission: web= manage

I deployed it on app store, but when I add the app it says "Sorry, something went wrong with adding the app."

I am not sure what I am doing wrong. Can you please guide me in this scenario?

Vardhaman Deshpande said...

Hi Zeba,

Can you re-create this problem by creating a new test app in VS?

Zeba said...

Hi Vardhaman, Iam facing above problem with a new app project only.

Zeba said...

Hi Vardhaman,

Other questions.
1. You mentioned not to use this trick in production and there will be tools deployed sooner.
My I know what another approach I can use to connect to my HostSite Custom list through app workflow. Please note I use O365.
2. In my above comment regarding workflow for discussion list(Host site), I would also like to understanding if I have messed up with some steps in the workflow, may b due to which it is failing.

Sorry to add so many comments but I see no other option to communicate. :)

Unknown said...

Hi Vardhman,
Any news if integrated workflow apps are now officially announced for Office365. I have a need where I want to deploy workflow via apps. Thanks.

Unknown said...

Hi Prashant,
This feature is official in SPO and available to use, yes.

Visual Studio also modified their latest tools so you no longer need to modify the app package after it's been built.

Please move to the latest VS release (2015) to try it out!

Thanks,
-Tim [MSFT]

Vardhaman Deshpande said...

I have updated the post with the steps to "officially" create an Integrated Workflow App (Add-In) in Visual Studio 2015.

Unknown said...

I have deplyoed my app in app catalog and added this app from app stapling to particular site collection but my integrated app workflow is not listed in the particular list.Please help me out on this issue?

Unknown said...

I have deplyoed my app in app catalog and added this app from app stapling to particular site collection but my integrated app workflow is not listed in the particular list.Please help me out on this issue?

Sudesh said...

Once i add the app to SharePoint online app catalog it shows "Valid App Package" value No.
Due to this app is not available to add in site collection. Any idea?

Philippe Horlaville said...

Hi, and thank you for this great article.
I have a particular need and maybe you can help me.
In my workflow deployed, i'm trying to create an item in a list also deployed by the add-in (so IN the app web).
Unfortunately, i got an error on the createlistitem activity when my workflow fires : "List does not exist3.
It seems that the workflow tries to find the list in the host web, not in the app.
When i build my worflow activity, in the ListId input, my list is shown :
(none)
(current list)
MyListName

When i click on the elipsis after selecting my list name, it shows "System.Guid.Parse("{$ListId:Lists/MyListName;}")

The workflow's error is :
"Retrying last request. Next attempt scheduled in less than one minute. Details of last request: HTTP NotFound to https://myhostwebdomain.sharepoint.com/myhostweb/_api/web/lists(guid'c2279cec-2c89-49be-ae8a-b714ed8cfe2c') Correlation Id: c0b7583d-c940-cf1c-a15a-e9a09c704e89 Instance Id: 3c97da05-c38a-47a2-929d-f1784456967d

List does not exist.

The page you selected contains a list that does not exist. It may have been deleted by another user.
Retry now "
It is obvious that it tries to find my list in the host web, and not in the app web.
Do you know any way to achieve this ?

Thanks in advance,

Philippe

Unknown said...

Hi Philippe,

Integrated workflow add-ins are configured at the add-in level, so you cannot mix and match one portion of a workflow to address the add-in site and another to address the parent site. All workflow calls will focus on the parent site.

Thanks,
-Tim [MSFT]

Philippe Horlaville said...
This comment has been removed by the author.
Philippe Horlaville said...

Thank you Tim for your reply.
So I'll try to create my list first (in my host web), and the deploy my workflow.
Do you know if there's a way to get a host web list guid from an integrated workflow activity?

Philippe Horlaville said...

I found this link, i'm now able to retrieve my list id from the Title with Rest, and so to create an item in my host web list.
http://www.sharepoint-journey.com/rest-api-in-visual-studio-workflow-in-sharepoint-hosted-app.html

Thanks a lot.

Philippe

sgaurav said...

Hi Vardhaman, Will SharePoint Online Integrated Workflow Apps works on office 365 dedicated?

Unknown said...

Hi Vardhaman, is it possible to get the contents from another subsite using REST call from the workflow in the App if Full control Permission is given for site collection

Koen Zomers said...

The good news is that in SharePoint 2016 RC for On Premises it works as well. So this functionality is coming to On Premises as well. For Visual Studio 2013 with the at present latest update you still have to hack it into the Add-In package, for Visual Studio 2015 you have the handy switch in the properties as mentioned above.

Jeffrey McFarland said...

I'm also having the same issue as the above poster "Martin Sørensen". I can't get the list workflow to start on item created or updated. It Works when I start it manually, I have also noted that I don’t get the option to select “manually”, “Item created” or “Item changed” in VS as shown on image 18 in your tutorial. I'm using VS 2015 with Office dev tools installed.

Unknown said...

Thanks Vardhaman for such a wonderful article.
It helped me a lot to start me understanding the SP WF integrated apps.

Great job Buddy!! :)

Raghu said...

Hi, after deployment if any change in workflow how to update?

Thanks

Unknown said...

Hi Raghu,

You need to do a full app upgrade to change the workflows.

Thanks,
-Tim [MSFT]

Saket said...

Hi Vardhaman,

I have created a SharePoint Integrated Workflow App using SharePoint Hosted Add-in in SharePoint 2016. The workflow is attached to the item created event on host web library.

The Workflow works fine if we add the document manually but does not trigger with the incoming emails.

We created a demo SPD workflow on the same library and it works fine with incoming emails. We are facing issue with only SharePoint Integrated Workflow App.

Thanks!