Step by step develop workflows using visual studio 2015 as an add in and deploy to host web in SharePoint online?

sharepoint online workflow visual studio example
InfoPath alternatives for form designing SharePoint

Here we will discuss how we can create workflow using visual studio 2015 for SharePoint online site and also we will see how we can deploy to host web list or library. This is going to be a very simple workflow but we are going to understand how to do this with steps.

Since we are going to develop as an SharePoint hosted add-in, make sure you have a developer site is ready which you. You can check an article on how to create a developer site for SharePoint online Office 365.

Also you can read some useful articles on:
– SharePoint Online Site Workflow and Initiation Form Parameters example using SharePoint designer workflow

– Introduction to cloud computing and Microsoft Azure

– How to use client side People Picker control in SharePoint online Office 365?

Follow below steps:

Open visual studio 2015 and then File -> New -> Project. And then in the New Project dialog box, choose SharePoitn Add-in from Templates ->Visual C# -> Office/SharePoint like below:

SharePoint visual studio workflow
SharePoint visual studio workflow

Then in the Add-in settings dialog box, give SharePoint online developer site url and choose the host type for SharePoint Add-in as “SharePoint-hosted”.

SharePoint visual studio 2015 workflow
SharePoint visual studio 2015 workflow

Then it will ask for credentials to connect to SharePoint online site. Once entered successfully, it will show the below screen.

SharePoint online visual studio 2015 workflow
SharePoint online visual studio 2015 workflow

Now the SharePoint Add-in project will look like below:

SharePoint 2013 visual studio 2015 workflow
SharePoint 2013 visual studio 2015 workflow

To make the workflow available in the host web we need to choose “Integrated App” project properties to true. But since we have not added Workflow yet, you will not be able to see the “Integrated App” project properties.

SharePoint 2016 visual studio 2015 workflow
SharePoint 2016 visual studio 2015 workflow

Next we will add a the Workflow to the project. Right click on the Project, Add -> New Item. And in the Add New Item dialog box, choose Visual C# Items -> Office/SharePoint. And then choose Workflow template like below:

Deploy Workflows to Host Web with Integrated Workflow
Deploy Workflows to Host Web with Integrated Workflow

Then in the next screen, give a workflow name and choose List Workflow in the type of workflow like below:

how to deploy workflow to host web sharepoint online
how to deploy workflow to host web sharepoint online

Then in the Select the lists you will use when debugging screen, uncheck the check box and do not select anything like below:

how to debug visual studio 2015 workflow sharepoint
how to debug visual studio 2015 workflow sharepoint

Then the workflow will be added to the project and it looks like below:

debug sharepoint online visual studio workflow
debug sharepoint online visual studio workflow

Now click on F4 in the project to open the Project properties and there change the Integrated App property to True like below:

sharepoint online visual studio workflow
sharepoint online visual studio workflow

Now in the workflow search for a WriteToHistory action and click on the Message in the Properties box. There write some message as a string like below:

sharepoint online visual studio workflow
sharepoint online visual studio workflow

So this is a very simple workflow having one activity only. Now open the AppManifest.xml file and give Web to manage or full control permission like below:

how to create workflow in sharepoint 2013 using visual studio
how to create workflow in sharepoint 2013 using visual studio

Now we will try to publish the workflow to the SharePoint online site. Right click on the Project and click on Publish… like below:

sharepoint 2013 workflow visual studio example
sharepoint 2013 workflow visual studio example

This will open the Publish your add-in page, here click on Package the add-in which will generate the .app file like below:

sharepoint online workflow visual studio example
sharepoint online workflow visual studio example

Now we need to open the .app file using 7-zip or similar tool like below:

sharepoint 2013 approval workflow using visual studio
sharepoint 2013 approval workflow using visual studio

Then open the WorkflowManifest.xml file and check if the below tag is there or not.

<IntegratedApp>true</IntegratedApp>

If not add it and save the file.

Now it is the time to upload the .app file into the App Catalog site. Once it is uploaded to the App Catalog site, We can add into any SharePoint site, Site Contents > Add an App > Select your app and add it to your Team Site.

If it ask to trust, Trust it.

Now open any list and from the ribbon click on List Settings -> Workflow Settings and then click on Add a Workflow. In that screen you will see two options in Available Apps. One is for This List and another one as your App name (Here in my case it is ApprovalListWFHostWeb). In the Workflow details Click on the <Workflow Name>(in my case the name is ListApprovalWorkflow) like below:

how to create workflow in sharepoint online using visual studio
how to create workflow in sharepoint online using visual studio

Then give a name for the workflow and also you can select Task List & History List. Also choose the Start Options like when you want to start the workflow.

visual studio 2015 sharepoint 2013 workflow
visual studio 2015 sharepoint 2013 workflow

Now if you will again go back to the Workflow settings page, you can see the workflow is attached to the list like below:

visual studio 2015 sharepoint online workflow
visual studio 2015 sharepoint online workflow

Now it is time to start the workflow manually for one item in the list. For this select an item from the list, then click on ECB menu -> Advanced -> Workflows.

visual studio 2015 sharepoint 2016 workflow
visual studio 2015 sharepoint 2016 workflow

Then click on the workflow app and then you can see the workflow under Start a New Workflow like below:

Debug visual studio 2015 workflow sharepoint online
Debug visual studio 2015 workflow sharepoint online

Once the workflow got started successfully, you can see it will write the message which we have added inside the WriteToHistory activitity like below:

how to debug visual studio 2015 workflow in sharepoint 2013
how to debug visual studio 2015 workflow in sharepoint 2013

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply