Reusablility is one of the key features of Nintex Workflow and what makes it stand out. When it comes to building workflows, the aim is to automate some business logic so that employees spend more time on more important business tasks. You may have a complex business scenario that is quite laborious, but if you can automate this, your business becomes efficient, expenses are reduced, revenue gets increased and your business becomes more profitable.
When you sit down and start mapping out what processes you can automate, inevitably, you'll find that there a many processes that are very similar. If you start building a workflow for these business processes, you don't want to build the same logic over and over again. Again, we come back to reusablility and efficiency. It's not efficient to have multiple processes that perform the same functionality but designed a little different.
This is where start thinking about reuse with Nintex Workflow.
Definition of a User Defined Action
A User Defined Action is one way of building what is essentially a custom action that will appear in the Workflow Designer page. When you build a User Defined Action (aka UDA), this action can be scoped to the site, site collection or farm*.
You can think of this as a workflow in a box. Designing a UDA is just the same as designing a workflow. It wraps a bunch of actions inside it, and the UDA can take any number of input and output parameters.
When it is published, it will appear in your workflow designer page just as any other action, but the contents of which are hidden from the designer (user).
Why do I need a User Defined Action
There are a number of reasons to use UDAs.
Since we don't want to build the same complex logic more than once, we build it in a UDA and then we can use this in any workflow, rather than having to build it again.
Also, if you make changes to the UDA and publish it, you are given the option to republish and workflows that use this UDA, so they are kept up to date.
2. Hiding logic
You will encounter users that need to build workflows, but their techincal skills are limited. When it comes to needing data from a database or from a web service call, they may not be able to do this on their own.
A more technical person can build a UDA, put it any database calls or web service calls, expose some parameters and then the business user will be able to use this UDA in their workflows without knowing all the nuts and bolts.
How do I create a User Defined Action?
The simplest way to create a UDA, is to login to your SharePoint site, click on Site Actions > Nintex Workflow 2010 > Manage User Defined Actions.
Here you can create, import, export modifiy, promote and delete UDAs. You can also Analyze a UDA, so that you can tell which workflows are using it.
As you can see from the screenshot below, the designer page for a UDA looks identical to the workflow designer page, except for the mention of User Defined Action at the top right:
User Defined Action Parameters
Just like regular actions in Nintex Workflow, UDAs can have input and output parameters.
eg. If you were to create a UDA that would add two numbers together, you would have 2 input parameters (the 2 numbers) and 1 output parameter (the result).
Adding parameters to the UDA, you simply click on the drop down for UDA Settings and select Parameters.
We simply add out parameters here, and make sure we configure the types to be what we need (input/output).
You then use these parameters as you would use variables in a workflow.
User Defined Action Promotion
When you first publish a UDA, it is considered a Team Site User Defined Action. It will only be available in the workflows you design on this site.
On clicking the Promote button on the ribbon, you'll be given a confirmation window popup and then it will promote it to a Site Collection scoped UDA. This means that any workflow, in any site in this site collection will be able to use this UDA.
Now you can switch to Site Collection Level Settings, and you'll be able to once again promote this UDA to now be Farm scoped. Now any workflow in your farm can use this UDA.
You'll now see this action in Central Administration > Nintex Workflow Management > Manage User Defined Actions
As you can see, there is no Modify button for Farm scoped UDAs. In order to make any changes, you'd need to export, import, modify and promote again.
Importing and Exporting User Defined Actions
There are actually 2 ways to import/export a UDA.
1. When you are designing a UDA, just as you would with a Nintex Workflow, on the ribbon, there's an Export button which will export the UDA to a .NWF file.
Consider this the UDA design. Even though it has a .nwf extension, it can not be imported into the regular Nintex Workflow designer page. It can only be imported in the User Defined Action designer page. So if you download a .nwf action, you'll need to go Manage User Defined Actions, click on Create and when you see the design page, click on the Import button.
2. On the Manage User Defined Action page, as you saw in the screenshot above, there's an Export button.
Think of clicking on this, as exporting the action itself. This will result in a file with a .UDA extension.
To import this, you'll need to go to the Manage User Defined Actions and on the ribbon, click on the Import button.
You may be asking, what is the difference?
If you have a workflow (WorkflowA) that uses a user defined action, it is linked to the action itself and not the design. If you import the .UDA file and publish it, then import WorkflowA that uses it, it will automatically recognize that the UDA is there and you simply publish the workflwo and all will be great.
On the other hand, if you import the .NWF user defined action and publish it, when you import the WorkflowA, it won't see the UDA because the published version now has a different internal ID.
When moving UDA and Workflows between environments, I'd recommend exporting the UDA from the Manage User Defined Action page. This will preserve the connectivity between workflow and UDA.
Effects on a Workflow
Using a UDA will increase the overall size of the workflow at runtime. The size of the workflow can affect the starting of the workflow, especially the first time after an app pool recycle.
So you should be made aware of this. But the thing to note is that the logic in the UDA would have been something you added to the workflow anyway. By using a UDA, if you need to change it to make it better, you change it in one place and have it automatically republish each workflow that uses it and you've now updated all your workflows.
* - farm scoped User Defined Action can not be edited at this stage. So if you promote a UDA to be farm scoped and you want to edit, you'll need to export it, import it, edit it and promote it.