Adding a CheckBox to a FIM Custom Workflow UI

The only examples of custom workflows I’ve seen so far use text boxes for all data entry on the UI. Here’s how I went about adding a check box to my UI.

Note: I have also posted a version of this to the Technet Wiki: How to Add a CheckBox to a FIM Custom Workflow UI


The code I’m sharing here adds an “Enabled” checkbox to the workflow UI in the FIM Portal. Whether or not it is ticked returns a boolean value which you can then reference in your code.

Define the boolean property in the Activity code

This is pretty much like the regular way UI properties are defined, just typing it as a Boolean instead of a String.

    '''
    '''  Identifies the target attribute
    '''
    Public Shared WFEnabledProperty As DependencyProperty = DependencyProperty.Register("WFEnabled", GetType(System.Boolean), GetType(MyActivity))
    <Description("Please specify the target attribute")> _
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    <Browsable(True)> _
    Public Property WFEnabled() As Boolean
        Get
            Return DirectCast(MyBase.GetValue(MyActivity.WFEnabledProperty), [Boolean])
        End Get
        Set(ByVal value As Boolean)
            MyBase.SetValue(MyActivity.WFEnabledProperty, value)
        End Set
    End Property

 

UI code functions

Add the following functions to your UI code:

#Region "CheckBox Functions"
    Private Function AddTableRowCheckBox(ByVal labelText As [String], ByVal controlID As [String], _
                                         ByVal defaultValue As [Boolean]) As TableRow
        Dim row As New TableRow()
        Dim labelCell As New TableCell()
        Dim controlCell As New TableCell()
        Dim label As New Label()
        Dim checkbox As New CheckBox()

        label.Text = labelText
        label.CssClass = MyBase.LabelCssClass
        labelCell.Controls.Add(label)

        checkbox.ID = controlID
        checkbox.Checked = defaultValue

        controlCell.Controls.Add(checkbox)
        row.Cells.Add(labelCell)
        row.Cells.Add(controlCell)
        Return row
    End Function

    Private Function GetIsChecked(ByVal checkBoxID As String) As Boolean
        Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)
        Return checkBox.Checked
    End Function

    Private Sub SetIsChecked(ByVal checkBoxID As String, ByVal isChecked As Boolean)
        Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)
        If checkBox IsNot Nothing Then
            checkBox.Checked = isChecked
        Else
            checkBox.Checked = True
        End If
    End Sub

    Private Sub SetCheckBoxReadOnlyOption(ByVal textBoxID As String, ByVal [readOnly] As Boolean)
        Dim checkBox As CheckBox = DirectCast(Me.FindControl(textBoxID), CheckBox)
        checkBox.Enabled = Not [readOnly]
    End Sub

#End Region

 

Modify the default methods of the UI code

Finally modify the default metods of the UI code to handle the value.

    Public Overrides Function GenerateActivityOnWorkflow(ByVal workflow As SequentialWorkflow) As Activity
        If Not Me.ValidateInputs() Then
            Return Nothing
        End If
        Dim MyActivity As New MyActivity()
        MyActivity.WFEnabled = Me.GetIsChecked("bWFEnabled")
        Return MyActivity
    End Function

    Public Overrides Sub LoadActivitySettings(ByVal activity As Activity)
        Dim MyActivity As MyActivity = TryCast(activity, MyActivity)
        If MyActivity IsNot Nothing Then
            Me.SetIsChecked("bWFEnabled", MyActivity.WFEnabled)
        End If
    End Sub

    Public Overrides Function PersistSettings() As ActivitySettingsPartData
        Dim data As New ActivitySettingsPartData()
        data("WFEnabled") = Me.GetIsChecked("bWFEnabled")
        Return data
    End Function

    Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData)
        If data IsNot Nothing Then
            Me.SetIsChecked("bWFEnabled", DirectCast(data("WFEnabled"), Boolean))
        End If
    End Sub

    Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode)
        Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View)
        Me.SetCheckBoxReadOnlyOption("bWFEnabled", [readOnly])
    End Sub

    Protected Overrides Sub CreateChildControls()
        Dim controlLayoutTable As Table
        controlLayoutTable = New Table()

        'Width is set to 100% of the control size
        controlLayoutTable.Width = Unit.Percentage(100.0)
        controlLayoutTable.BorderWidth = 0
        controlLayoutTable.CellPadding = 2
        ' The following line adds the CheckBox
        controlLayoutTable.Rows.Add(Me.AddTableRowCheckBox("Enabled:", "bMyCheckBox", True))
        Me.Controls.Add(controlLayoutTable)

        MyBase.CreateChildControls()
    End Sub

 

Using the value

Once all that’s done I simply access the value in my Activity code using Me.WFEnabled.

Leave a Reply

Your email address will not be published. Required fields are marked *


*