Association form in Visual Studio 2013 workflows



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 Form in Workflows

Association forms are important to configure the workflow to the specific list or library.

In the association form, you will define

  • what is the Name of the workflow
  • History and task lists that will get associated with
  • start options whether you need to start manually or when item added or updated within in the list/library and
  • you can add additional configuration, according to the requirements.

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.

Like to see how to build association form using Visual Studio 2013 ?. We have added the video for you. Please go ahead and watch it here.

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 learn more about Building workflows, click the image below and enroll in the FREE course.

Add workflow to the Project

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.

Add Association to Workflow

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.

Association Form before

Below code is the default one that will get added once you add the form to the project. Once you add the association form, all the HTML and JavaScript required will be added by the template itself. You need to make the change, according to your requirement.

You can ignore the comments from line 14 to 18 in the below snippet that are getting added in the form.

In Line 26 you have "WorkflowAssociationFormContextControl" which is responsible to load the all the required JavaScript files such as SP.Js, SP.Runtime.Js and SP.WorkflowServices.Js.

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.

Association Form After

We have modified the form as per requirement to keep only on text box control(Line number 22). And similarly we have to update the "metadata" object in the JavaScript section( Line numbers 81 to 84).

Workflow Activities:

In this workflow, we will use below workflow activities on how to develop association form in workflows using Visual Studio 2013.

  • GetConfigurationValue
  • WriteToHistory

Adding workflow activities to develop association form

GetConfigurationValue:

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.

Workflow Variables:

We have created "strArg" variable to store the configuration value from association form.

Completed workflow:

Once you complete, all steps workflow will get complete. Please see the below screen.

Testing:

Right-click on the project and click on deploy. Once you deploy it, then attach association form to List.

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.

Code Repository:

You can download the code by clicking on the image below.

Do you want to watch how to build to Association forms?

 

P.S. You can use below chapter to skip to a specific section in this video.

Conclusion:

In this post, you have learned how to add association form in Visual Studio 2013 workflows.

To learn more about Building workflows, click the image below and enroll in the FREE course.

› Association form in Visual Studio 2013 workflows



Join 6,500 subscribers and receive instant access to

Devendra's Library of Resources for SharePoint Developers


About Author

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.