This article shows you how to add a CheckBox to the UI part of your FIM custom workflow.

Applies to

  • FIM 2010 and later,
  • MIM 2016 all versions

UI code functions

Add the following functions to your workflow's UI class:

#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

 

Define a Boolean property in the Activity code

In your workflow's Activity code you need to define a Boolean property which will represent whether the CheckBox is ticked in the FIM Portal workflow configuration:

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

Add the CheckBox to the UI

You also need to modify the default methods of the UI class to render the CheckBox.

 

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.MyCheckBox = Me.GetIsChecked("bMyCheckBox")
 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("bMyCheckBox", MyActivity.MyCheckBox)
 End If
 End Sub
  
 Public Overrides Function PersistSettings() As ActivitySettingsPartData
 Dim data As New ActivitySettingsPartData()
 data("MyCheckBox") = Me.GetIsChecked("bMyCheckBox")
 Return data
 End Function
  
 Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData)
 If data IsNot Nothing Then
 Me.SetIsChecked("bMyCheckBox", DirectCast(data("MyCheckBox"), Boolean))
 End If
 End Sub
  
 Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode)
 Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View)
 Me.SetCheckBoxReadOnlyOption("bMyCheckBox", [readOnly])
 End Sub
  
 Protected Overrides Sub CreateChildControls()
 Dim controlLayoutTable As Table
 controlLayoutTable = New Table()
 controlLayoutTable.Width = Unit.Percentage(100.0)
 controlLayoutTable.BorderWidth = 0
 controlLayoutTable.CellPadding = 2
 ' The following line adds the CheckBox
 controlLayoutTable.Rows.Add(Me.AddTableRowCheckBox("MyTitle:", "bMyCheckBox", True))
 Me.Controls.Add(controlLayoutTable)
  
 MyBase.CreateChildControls()
 End Sub

 

Using the value in your Activity code

To access the CheckBox value in your Activity code simply use Me.MyCheckBox.

References