NüWorkflow Custom Tasks

This article explains how to write the code for a simple custom task and integrate the compiled DLL with NüWorkflow.

Step 1: Open Microsoft Visual Studio:

Step 2: Open the New Project dialog:

Step 3: Choose the Class Library project type:

Must use .NET 4.0 or newer.

In the above, “CompanyXYZ” represents the name of your company. However, it can be named whatever you choose. NüWorkflow does not require any naming convention. “CompanyXYZ.Opulos” was chosen because it represents a bridge between two worlds.

Step 4: Write a new public static method:

In order to be accepted by NüWorkflow, the method must be “public static” and the method inputs must be of types known to NüWorkflow. In this particular example, the method inputs are a DateTime, a database connection and a MailMessage object. Part 2 goes into detail about all the types of inputs that can be used.

Step 4: Compile the code

The code is so simple, there should be no compile errors. The compiled DLL will be in either the “Debug” or “Release” folder depending on the Project Properties → Build → Configuration setting. Debug or Release is up to you. Debug is useful because the line numbers will be preserved if an exception happens. It will make tracking down errors and fixing them much quicker.

Typically you will copy your DLL to a company network drive, so that NüWorkflow can read the file from any computer it is running on. If you keep the DLL on your local C: drive, then only NüWorkflow running on your local computer will be able to access those tasks. (Note: future versions of NüWorkflow may support loading multiple DLLs and the DLLs may be saved in a database). For now, we can use the DLL where it is.

Step 5: Open NüWorkflow

Goto NüWorkflow → System Settings. Then in the “Custom Assembly Filename” field, enter the full path to the DLL, and then click the ‘Save All’ button:

Step 6: Add New Task

We are close to the end. Now just edit an existing workflow or add a new one. In the workflow, add a new task. Then click the “Browse…” button:”

Step 7: Select Your Method!

In the “Category” drop down box, select “Custom”. Your “DoSomething” static method will appear. Notice that the “Method Description” and param “Information” are blank. To set these, simply add the [Description(“…”)] attribute to the method and its inputs. This is covered in more detail in Part 2.

Step 8: Setting the Inputs

At this point, your DLL is integrated. This section explains how NüWorkflow manages task inputs. Recall that your method took in three inputs: a DateTime, a database connection, and a MailMessage object. Each method input is converted to a corresponding user-interface control where the value can be set:

  1. DateTime: Here you can specify a fixed date, such as “2015-03-15″. However, more likely you will use a date equation, such as bd-1 (previous business day), and select which Calendar defines the holidays. If a country or province introduces a new holiday, then all you have to do is add that holiday to the calendar, and all the tasks that use that calendar are automatically updated.
  2. IDbConnection: Here you select one of the databases from the databases defined in System. If at some point, a database needs to point to a different server, then all you have to do is edit the connection string on the database screen, and all the tasks are automatically updated.
  3. MailMessage: This input is hidden because it is automatically created by NüWorkflow and passed as a parameter to your method. Your method can optionally set the “Body” and “Subject” properties. All you have to do is setup an “Email Template” that defines the recipients (this is the preferred way), or you can specify the recipients in the “Email To” field. It’s preferred to use an Email Template because if you have multiple tasks that have the same recipients, and you have to add or remove someone from the list, then using an Email Template means only having make a single edit, rather than having to change the recipients in each task. Also, NüWorkflow handles the sending of your email by using the SMTP Servers defined in System.

NuWorkflow Does the Work

NüWorkflow does the work of turning the date equation into a DateTime object. NüWorkflow does the work of opening and closing the database connection. NüWorkflow does the work of creating the MailMessage, then does the work of deciding to send it (must have a non-empty body and at least one recipient), and does the work of sending the email (trying the primary SMTP server first, and falling back to the secondary SMTP server if the first fails). Hopefully this demonstrates how NüWorkflow provides a structured framework for developers to write their own custom tasks.