Posted on July 9th, 2015
In this post, you will learn how to develop Association form in Visual Studio 2013 workflows.
Please check my previous blog post, step1 and step 2 on how to create a list workflow.
We are sharing on workflows in SharePoint 2013 and Office 365 using Visual Studio 2013. These apply to both on-premises and online. All these blog posts here based on SharePoint hosted add-ins(apps).
Association forms are important to configure the workflow to the specific list or library.
In the association form, you will define
These requirements can be setting default approves for each department or storing credentials of a web service for a specific client, etc.
You can see in the below figure, we are using association form to attach the OOB(Out of the box) approval workflow to the List or Library.
In the below figure, we have a project called "Finance Approval" which is SharePoint hosted add-in(app). Within this, we have a list with the name "Finance Info".
To the existing project will add a workflow called "Finance Approval." To add a workflow, right-click on the project, Add, New Item and select workflow template as shown in below figure and click Add.
Here we are going select the type of workflow as List workflow, once it is selected, click on Next.
Below one is important setting where we don't have to associate the workflow to the List.
We are building a custom association form to this workflow, so un-check the option "Would you like Visual Studio to automatically associated the workflow?" and click Finish to add the workflow to the project.
To add an Association form to the workflow, you need to select workflow then click on Add, New Item and select the Workflow Association form shown in the below figure.
Note: If you try to add the association form from the project it will not be available, it will be available in the context of workflow only.
You can ignore the comments from line 14 to 18 in the below snippet that are getting added in the form.
You can modify the HTML from line number 31 to 39 to show which controls need to be displayed on the association form to configure.
In line number 89 metadata is responsible to store the values that you have entered while configuring the association form.
You can also see that in the lines 117, 135 it will check if the Workflow history list and Task list available or not, if not then this form will create those two lists.
In this workflow, we will use below workflow activities on how to develop association form in workflows using Visual Studio 2013.
To get current list item, we need to work with "GetConfigurationValue" workflow activity. In the Visual Studio 2013 you can specify the "Name" property to the metadata property we have to read it which is nothing but "strArg" from the above code snippet.
We have created "strArg" variable to store the configuration value from association form.
Once you complete, all steps workflow will get complete. Please see the below screen.
Right-click on the project and click on deploy. Once you deploy it, then attach association form to List.
We need to attach the workflow to the list, to do that go to List Settings, Workflow Settings and Select the Finance Approval workflow. Please see the screen below to fill other details like name, Workflow history list, task list and start options.
Once you completed the above configuration, click on the Next button to fill the String value we have configured in the association form. Enter some text here for example "Association form demo".
Add an item in the Finance Info list and it should start the workflow based on start options you have configured in association form. Now go to workflow status page to see the history info we have written for message entered while configuring the form. Please see below screen.
You can download the code by clicking on the image below.
P.S. You can use below chapter to skip to a specific section in this video.
In this post, you have learned how to add association form in Visual Studio 2013 workflows.
Devendra Velegandla is a four-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2017) for Office Servers and Services MVP and SharePoint Server.He received the MCC award for his contributions in Microsoft MSDN/TechNet forums.He loves sharing articles, videos and tutorial on SharePoint and Office 365.