If you have a boolean property on your Windows Workflow Activitiy, you will probably expect a checkbox on your form. How do you map the values correctly?
The Windows Workflow Activity
If you follow the Nintex documentation for creating a custom action, you will create a Windows Workflow Activity. This is accessed via code in the Nintex project in your solution, so you can implement something quite cut-down (without need for designer support, for example). You will typically inherit from System.Workflow.ComponentModel.Activity. Here is an example:
public sealed class FileCopyActivity : Activity
{
public static DependencyProperty OverwriteProperty = DependencyProperty.Register("Overwrite", typeof(bool), typeof(FileCopyActivity));
[Description("Overwrite behaviour if destination file exists - if true, overwrite, else create new file with date appended to name")]
[Category("FileCopy")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public bool Overwrite
{
get
{
return (bool)base.GetValue(FileCopyActivity.OverwriteProperty);
}
set
{
base.SetValue(FileCopyActivity.OverwriteProperty, value);
}
}
...
The Nintex Action, Adapter and Settings Dialog
OK, so you can compile your activity with any other properites, your logic, etc. and then deploy it. Now, in your Nintex project, you will have a class inheriting from Nintex.Workflow.Activities.Adapters.GenericRenderingAdapter and an aspx Page for your dialog where the user configures the settings. Your markup for the checkbox control might look like this:
<div class="RowBlue">
<span class="Label">Overwrite existing</span>
<input type="checkbox" class="" id="overwrite" />
</div>
Now, how do you plumb this to the Boolean property on your Activity? The problem is that you have an xml structure which is expecting there to be a text node or property, and a backend boolean. Also, you have a control on your form whose "checked" property is controlling whether the checkbox is checked or not. My answer was to use the fact that the string conversion of .Net System.Boolean values uses "false" and "true" as strings. The Nintex documenation tells you that you need to implement a couple of JavaScript functions. The following markup will do the right conversion for you:
<asp:Content ID="ContentHeader" ContentPlaceHolderID="AdditionalPageHeader" runat="server">
<script type="text/javascript" language="javascript">
var FIRSTQUAD = FIRSTQUAD || {};
function TPARetrieveConfig() {
FIRSTQUAD.overwriteCtrl = document.getElementById("overwrite");
var overwrite = configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Overwrite']
/PrimitiveValue/@Value").text;
FIRSTQUAD.overwriteCtrl.checked = (overwrite === "true");
}
function TPAWriteConfig() {
configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Overwrite']
/PrimitiveValue/@Value").text = FIRSTQUAD.overwriteCtrl.checked ? "true" : "false";
return true;
}
</script>
</asp:Content>
Global Variable Danger
Note that Nintex documentation tells you to create global variables for your controls. This is bad practice. What you see above is the Namespace Pattern in use to define a single global entry point for all our company's data. In actual fact, you shouldn't really have to implement the two functions as globals, rather as members of some object, but there is not much we can do about that.