Using Custom Task Forms with Nintex Workflow – Example Solution

This is the follow-up post for the Using Custom Task Forms with Nintex Workflow and is an example implementation of the custom task form using dynamic loaded user controls. The way this works is that the CustomForm.aspx is called by the Nintex workflow task along with some parameters. With this a context is created containing some variables associated with the workflow. The content type name is parsed so that the correct user control is loaded. To get start with the solution, please follow these steps:

  1. Deploy the solution from visual studio to your SharePoint site.
  2. Add the workflow to a list (DemoWorkflow.nwf). Create a custom one, doesn’t matter, just so you can start the workflow on a list item.
  3. Edit the script (nintex.contenttype.bat) to set the correct SharePoint URL, and run it.
  4. Start the workflow on a list item, and check the Workflow Tasks list. If everything went right you should have a task here, and when you click it you will see the custom form show a dynamic loaded user control with a link to my wonderful blog.

You can download the solution here.

Using Custom Task Forms with Nintex Workflow

In this blog I want to show you how to create powerful task forms for Nintex using application pages. Later on I will add an example solution with some help functions and a mechanism to use user controls as the forms. (Update: You can find the example solution here.)

Why?

Well, because you want more. Nintex workflow already supports InfoPath or Nintex Forms, but in my opinion tools like this will always have limits the moment you want something more than just editing and validating user input. Sometimes you just want the flexibility of ASP.Net. There is an example of a custom task from in the Nintex SDK. I stripped that example, so that I can use my own forms and handling of tasks. The way this works is that if you want to use a custom application page to handle a Nintex task, you create a content type based on the Nintex Content Types, associate this content type with an custom application page, and to use this in the workflow set the content type of one of the Request actions in the Nintex Workflow.

Step 1 – Create the custom content type

Go to site settings and add the content type. See image for the correct settings.

Figure 1 – Create the Nintex content type

Step 2 – Create the application page

An example solution will be added to the blog later on. Add an application page to a SharePoint solution, reference the Nintex assemblies and inherit the page from ‘Nintex.Workflow.ServerControls.NintexLayoutsBase’. Runtime two parameters will be interesting to use, these are task list id and task list item id. In my example I have a helper to use these parameters to create a context object containing objects relevant to the workflow, task, list, list item etc.

Figure 2 – Code to create the context object

Step 3 – Register application page and content type

This can now be deployed. You now know where you deployed, what the url to the application page is and what the content type’s name is. We want to let Nintex know this too, for this nwadmin.exe is used. This application can be found in the Nintex installation directory. The command is used like this:
nwadmin.exe -o SetTaskForm -siteUrl “http://yoursite/” -contentType “YourContentTypeName” -taskformUrl “_layouts/YourApplicationPage” -formType All -updateChildren Yes

Step 4 – Set the Nintex action to custom content type

Finally, we must tell the workflow action to use the custom content type so that when the user opens the task, our page is shown. Select the correct action you want to use, and set the Task content type. Publish the workflow and you’re done.

Figure 3 – Set the custom content type