{"id":1213,"date":"2011-01-04T18:30:46","date_gmt":"2011-01-04T18:30:46","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=1213"},"modified":"2011-01-21T11:07:04","modified_gmt":"2011-01-21T11:07:04","slug":"adding-a-checkbox-to-a-fim-custom-workflow-ui","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/adding-a-checkbox-to-a-fim-custom-workflow-ui","title":{"rendered":"Adding a CheckBox to a FIM Custom Workflow UI"},"content":{"rendered":"<p>The only examples of custom workflows I&#8217;ve seen so far use text boxes for all data entry on the UI. Here&#8217;s how I went about adding a check box to my UI.<\/p>\n<blockquote><p>Note: I have also posted a version of this to the Technet Wiki: <a href=\"http:\/\/social.technet.microsoft.com\/wiki\/contents\/articles\/how-to-add-a-checkbox-to-an-fim-custom-workflow-ui.aspx\">How to Add a CheckBox to a FIM Custom Workflow UI<br \/>\n<\/a><\/p><\/blockquote>\n<p><!--more--><br \/>\nThe code I&#8217;m sharing here adds an &#8220;Enabled&#8221; 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.<\/p>\n<p><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/01\/checkbox-01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1214\" title=\"checkbox 01\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2011\/01\/checkbox-01.jpg\" alt=\"\" width=\"275\" height=\"29\" \/><\/a><\/p>\n<h3>Define the boolean property in the Activity code<\/h3>\n<p>This is pretty much like the regular way UI properties are defined, just typing it as a Boolean instead of a String.<\/p>\n<div><\/div>\n<p><code><\/p>\n<pre>    '''\r\n    '''  Identifies the target attribute\r\n    '''\r\n    Public Shared WFEnabledProperty As DependencyProperty = DependencyProperty.Register(\"WFEnabled\", GetType(System.Boolean), GetType(MyActivity))\r\n    &lt;Description(\"Please specify the target attribute\")&gt; _\r\n    &lt;DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)&gt; _\r\n    &lt;Browsable(True)&gt; _\r\n    Public Property WFEnabled() As Boolean\r\n        Get\r\n            Return DirectCast(MyBase.GetValue(MyActivity.WFEnabledProperty), [Boolean])\r\n        End Get\r\n        Set(ByVal value As Boolean)\r\n            MyBase.SetValue(MyActivity.WFEnabledProperty, value)\r\n        End Set\r\n    End Property<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n<h3>UI code functions<\/h3>\n<p>Add the following functions to your UI code:<\/p>\n<div><\/div>\n<p><code><\/p>\n<pre>#Region \"CheckBox Functions\"\r\n    Private Function AddTableRowCheckBox(ByVal labelText As [String], ByVal controlID As [String], _\r\n                                         ByVal defaultValue As [Boolean]) As TableRow\r\n        Dim row As New TableRow()\r\n        Dim labelCell As New TableCell()\r\n        Dim controlCell As New TableCell()\r\n        Dim label As New Label()\r\n        Dim checkbox As New CheckBox()\r\n\r\n        label.Text = labelText\r\n        label.CssClass = MyBase.LabelCssClass\r\n        labelCell.Controls.Add(label)\r\n\r\n        checkbox.ID = controlID\r\n        checkbox.Checked = defaultValue\r\n\r\n        controlCell.Controls.Add(checkbox)\r\n        row.Cells.Add(labelCell)\r\n        row.Cells.Add(controlCell)\r\n        Return row\r\n    End Function\r\n\r\n    Private Function GetIsChecked(ByVal checkBoxID As String) As Boolean\r\n        Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)\r\n        Return checkBox.Checked\r\n    End Function\r\n\r\n    Private Sub SetIsChecked(ByVal checkBoxID As String, ByVal isChecked As Boolean)\r\n        Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)\r\n        If checkBox IsNot Nothing Then\r\n            checkBox.Checked = isChecked\r\n        Else\r\n            checkBox.Checked = True\r\n        End If\r\n    End Sub\r\n\r\n    Private Sub SetCheckBoxReadOnlyOption(ByVal textBoxID As String, ByVal [readOnly] As Boolean)\r\n        Dim checkBox As CheckBox = DirectCast(Me.FindControl(textBoxID), CheckBox)\r\n        checkBox.Enabled = Not [readOnly]\r\n    End Sub\r\n\r\n#End Region<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n<h3>Modify the default methods of the UI code<\/h3>\n<p>Finally modify the default metods of the UI code to handle the value.<\/p>\n<div><\/div>\n<p><code><\/p>\n<pre>    Public Overrides Function GenerateActivityOnWorkflow(ByVal workflow As SequentialWorkflow) As Activity\r\n        If Not Me.ValidateInputs() Then\r\n            Return Nothing\r\n        End If\r\n        Dim MyActivity As New MyActivity()\r\n        MyActivity.WFEnabled = Me.GetIsChecked(\"bWFEnabled\")\r\n        Return MyActivity\r\n    End Function\r\n\r\n    Public Overrides Sub LoadActivitySettings(ByVal activity As Activity)\r\n        Dim MyActivity As MyActivity = TryCast(activity, MyActivity)\r\n        If MyActivity IsNot Nothing Then\r\n            Me.SetIsChecked(\"bWFEnabled\", MyActivity.WFEnabled)\r\n        End If\r\n    End Sub\r\n\r\n    Public Overrides Function PersistSettings() As ActivitySettingsPartData\r\n        Dim data As New ActivitySettingsPartData()\r\n        data(\"WFEnabled\") = Me.GetIsChecked(\"bWFEnabled\")\r\n        Return data\r\n    End Function\r\n\r\n    Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData)\r\n        If data IsNot Nothing Then\r\n            Me.SetIsChecked(\"bWFEnabled\", DirectCast(data(\"WFEnabled\"), Boolean))\r\n        End If\r\n    End Sub\r\n\r\n    Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode)\r\n        Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View)\r\n        Me.SetCheckBoxReadOnlyOption(\"bWFEnabled\", [readOnly])\r\n    End Sub\r\n\r\n    Protected Overrides Sub CreateChildControls()\r\n        Dim controlLayoutTable As Table\r\n        controlLayoutTable = New Table()\r\n\r\n        'Width is set to 100% of the control size\r\n        controlLayoutTable.Width = Unit.Percentage(100.0)\r\n        controlLayoutTable.BorderWidth = 0\r\n        controlLayoutTable.CellPadding = 2\r\n        ' The following line adds the CheckBox\r\n        controlLayoutTable.Rows.Add(Me.AddTableRowCheckBox(\"Enabled:\", \"bMyCheckBox\", True))\r\n        Me.Controls.Add(controlLayoutTable)\r\n\r\n        MyBase.CreateChildControls()\r\n    End Sub<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n<h3>Using the value<\/h3>\n<p>Once all that&#8217;s done I simply access the value in my Activity code using Me.WFEnabled.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The only examples of custom workflows I&#8217;ve seen so far use text boxes for all data entry on the UI. Here&#8217;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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[42,30,45],"tags":[],"class_list":["post-1213","post","type-post","status-publish","format-standard","hentry","category-fim-2010","category-vbnet","category-workflow"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-jz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=1213"}],"version-history":[{"count":7,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1213\/revisions"}],"predecessor-version":[{"id":1252,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/1213\/revisions\/1252"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=1213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=1213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=1213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}