Initiation form in Visual Studio 2013 workflows



Posted on July 5th, 2015

In this post, you will learn how to develop Initiation 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 based on SharePoint hosted add-ins(apps).

Initiation form in Workflows

Initiation form is used to enter values by end users who are starting the workflow manually.

For example, if your users want to add their manager name for the approval or enter some values that will used for each workflow instance that will be running. One of the prerequisites for this forms is you have to run the workflow manually. If your workflow is started automatically when the item added or updated then, initiations forms may not be the right choice. You need to look at the association form to implement or to take the configuration values for the workflows. 

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

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

The below figure shows the existing Change Management Approval workflow that is running on "Change Requests" list. We will add Initiation form to the one of the existing workflow. 

Adding Initiation form to the workflow

To add an Initiation form to the workflow, you need to select workflow then click on Add, New Item and select the Workflow Initiation form shown in the below figure.

Note: If you try to add the initiation form from the project it will not be available, it will be available in the context of workflow only.

Once the form added, the project shows as below figure where the form gets added to the Pages module by default.

Initiation Form Before

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

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

Line 27 to 36 represents the controls within the form.

Line 58 to 75 represents the object that will have values of the initiation form control.

Initiation Form after mofication

I have modified the above code to below one to meet my requirements. Here we had only one text box to enter the data and modified the wfParams object below according to the text box control we have.

Workflow Activities:

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

  • WriteToHistory

Workflow Arguments:

To capture the workflow parameters we can use the arguments in the workflow. Here "strArg" should match the parameter I am using in the above code snippet.

Workflow History:

To capture the argument value you can use the Workflow to History activity. Please see below image for the configuration.

Testing:

Right-click on the project and click on deploy. Once we deploy it, add an item in the Change Requests list and start the workflow manually.Once you start it, will open initiation form and enter some text "Initiation Form demo" in the text box.

Now go to workflow status page to see the history info we have written in the Initiation form. Please see below screen.

Code Repository:

You can download the complete source code from the link below.

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

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

 

P.S. You can use the chapters below to jump to different section of the video.

Conclusion:

In this post you have learned how to add an Initiation form in SharePoint 2013 or Office 365 workflows in Visual Studio 2013 workflows.

› Initiation 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.