<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2022-05-16T21:35:36.0000000">
    <CreatedUserId>Admin</CreatedUserId>
    <CreatedUtcDate>2018-08-27T23:03:57.1610000</CreatedUtcDate>
    <UpdatedUserId>Admin</UpdatedUserId>
    <UpdatedUtcDate>2022-05-16T21:34:56.2440000</UpdatedUtcDate>
    <ScriptId>WE</ScriptId>
    <Description>Workflow Edit</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Category />
    <Code>' HtmlWidget_WorkflowEdit
Option Explicit On
Option Strict On

' #################################################################
' Workflow Edit form HTML Widget
'
' Version: 1.03 (17/05/2022)
'
' Usage: System-supplied HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.02  27/03/2020  ISS                Updated
'    1.03  17/05/2022  ISS      J028483   Added Recall Date
' #################################################################

' Objects
Private mCombinedParameters As ISKeyValueList
Private mParameters As ISKeyValueList
Private mStartupParameters As ISKeyValueList

' Standard Parameters
Private mWorkflowId As String
Private mPage As String
Private mReadOnly As Boolean

' Other
Private mWorkflow As finWorkflow

Public Function Main(eventId As String,
                     parametersJson As String,
                     startUpParametersJson As String,
                     hostingContext As isefinHtmlWidgetHostingContext,
                     requestInfo As finScriptRequestInfo,
                     ByRef returnValue As String) As Boolean

  ' Assume Success
  Main = True

  ' Get Parameters
  mParameters = finBL.CreateKeyValueList()
  mParameters.FromSimpleJsonString(parametersJson)
  mStartupParameters = finBL.CreateKeyValueList()
  mStartupParameters.FromSimpleJsonString(startUpParametersJson)

  ' Get Combined Parameters (Startup Parameters updated with event Parameters)
  mCombinedParameters = mStartupParameters.Clone()
  mCombinedParameters.UpdateFromKeyValueList(mParameters, True)

  ' Get Standard Parameters
  With mStartupParameters
    mWorkflowId = .GetString("WorkflowId") ' Always use Startup Parameters since the Workflow Id may be updated
  End With
  With mCombinedParameters
    mPage = .GetString("Page")
    mReadOnly = .GetBoolean("ReadOnly")
  End With

  ' Handle Events
  Select Case eventId
    Case ""
      ' Main event, i.e., return initial HTML content (excluding html and body tags)
      returnValue = ScriptInfo.TemplateText

    Case "Finish"
      ' Finish wizard
      Main = Finish(parametersJson, requestInfo, returnValue)

   Case "GetInitialisationInfo"
      ' Get Initialisation Information required for this wizard
      Main = GetInitialisationInfo(returnValue)

    Case Else
      Main = False
      finBL.Error.ErrorBeginFormat("Unhandled event '{0}'", eventId)
  End Select

End Function

''' &lt;summary&gt;
'''  Load Workflow.
''' &lt;/summary&gt;
Private Function GetWorkflow() As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Shortcut
  If mWorkflow IsNot Nothing Then
    Return Success
  End If

  ' Validate
  If Len(mWorkflowId) = 0 Then
    Success = False
    finBL.Error.ErrorBegin("Workflow Id not specified.")
  ElseIf Not finBL.CurrentUser.Permissions.Allow("Workflow.Update") Then
    Success = False
    finBL.Error.ErrorBegin("You do not have permission to update Workflows.")
  End If

  ' Create and Load Workflow
  If Success Then
    ' Create Workflow
    mWorkflow = finBL.CreateWorkflow()

    ' Load Workflow
    If mWorkflow.Load(mWorkflowId) Then
      ' Validate
      If mWorkflow.IsNew Then
        Success = False
        finBL.Error.ErrorBeginFormat("Workflow '{0}' not found.", mWorkflowId)
      End If
    Else
      Success = False
    End If
  End If

  ' Clear Workflow if failed
  If Not Success Then
    mWorkflow = Nothing
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Initialisation Information required for this wizard.
''' &lt;/summary&gt;
Public Function GetInitialisationInfo(ByRef response As String) As Boolean

  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim Success As Boolean
  Dim swb As ISSqlWhereBuilder

  ' Assume Success
  Success = True

  ' Validate

  ' Get Workflow
  If Success Then
    Success = GetWorkflow()
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Form
      .PageId = mPage
      If finBL.Database.IsReadOnly OrElse mReadOnly Then
        .ReadOnly = True
      Else
        .ReadOnly = False
      End If

      ' Record
      .Pk = mWorkflow.Pk
      .Timestamp = mWorkflow.Timestamp

      ' Page Permissions (defined here since they are used below)
      .AllowPageGeneral = finBL.CurrentUser.Permissions.Allow("Workflow.Form.Page.General")
      .AllowPageusers = finBL.CurrentUser.Permissions.Allow("Workflow.Form.Page.Users")

      ' General
      .WorkflowId = mWorkflow.WorkflowId ' Always need to return Workflow Id
      If .AllowPageGeneral Then
        .Description = mWorkflow.Description
        .WorkflowTypeId = mWorkflow.WorkflowTypeId
        .WorkflowTypeDescription = mWorkflow.WorkflowType.Description
        .WorkflowTypeCategory = mWorkflow.WorkflowType.Category
        Select Case mWorkflow.WorkflowType.TargetObjectType
          Case isefinWorkflowTargetObjectType.Account
            .TargetObjectTypeText = "Account"
            .TargetObjectId = mWorkflow.AccountId
            .TargetObjectName = finBL.AccountFunctions.GetRecordDescription(.TargetObjectId)

          Case isefinWorkflowTargetObjectType.AccountApp
            .TargetObjectTypeText = "Application"
            .TargetObjectId = mWorkflow.AccountAppId
            .TargetObjectName = finBL.AccountAppFunctions.GetRecordDescription(.TargetObjectId)

          Case isefinWorkflowTargetObjectType.Client
            .TargetObjectTypeText = "Client"
            .TargetObjectId = mWorkflow.ClientId
            .TargetObjectName = finBL.ClientFunctions.GetRecordDescription(.TargetObjectId)
        End Select

        .Status = mWorkflow.Status
        .StatusText = mWorkflow.StatusTextResolved
        .FlagColour = mWorkflow.FlagColour
        .FlagNotes = mWorkflow.FlagNotes
        .ReviewDate = finBL.HtmlWidgetUtilities.GetNullableJsonUtcDateFromDatabaseDate(mWorkflow.ReviewDate)

        .AutoSuspendUntilDate = finBL.HtmlWidgetUtilities.GetNullableJsonUtcDateFromDatabaseDate(mWorkflow.AutoSuspendUntilDate)

        .TimeZoneId = mWorkflow.RecallTimeZoneId
        .RecallTzDate = finBL.HtmlWidgetUtilities.GetNullableJsonUtcDateTimeFromDatabaseDateTime(mWorkflow.RecallTzDate)
        .RecallImmediate = mWorkflow.RecallImmediate
        If Len(mWorkflow.RecallImmediateDetails) = 0 Then
          .RecallImmediateDetails = "The 'Recall Immediate' flag was set manually."
        Else
          .RecallImmediateDetails = "The 'Recall Immediate' flag was set due to the following events occurring:" &amp; vbNewLine &amp; vbNewLine &amp; mWorkflow.RecallImmediateDetails
        End If

        .Notes = mWorkflow.Notes
      End If

      ' Users
      If .AllowPageUsers Then
        .AllocatedUserId = mWorkflow.AllocatedUserId
        .PendingAllocatedUserId = mWorkflow.PendingAllocatedUserId
        .HoldAllocatedUser = mWorkflow.HoldAllocatedUser
      End If

      ' Other
      ' Allocated User (filtered based on Workflow Type)
      swb = finBL.Database.CreateSqlWhereBuilderForDataView()
      With swb
        .AppendRange("Pk", mWorkflow.WorkflowType.GetUserPksList(True).ToCsvString(), iseRangeDataType.Integer)
      End With
      .AllocatedUserSqlWhere = swb.SqlWhere

      ' Permissions
      If .ReadOnly Then
        .CanUpdateRecallDate = False
      Else
        .CanUpdateRecallDate = finBL.CurrentUser.Permissions.Allow("Workflow.RecallDate")
      End If

      ' Lists
      .FlagColourList = finWorkflowFunctions.CommonColourFlagsList

      ' Configuration
      .HideOtherPages = mCombinedParameters.GetBoolean("HideOtherPages", False)
      .PromptOnSave = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnSave
    End With
  End If

  ' Response
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(FormInitialisationInfo, response)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Finish, i.e., Save Workflow.
''' &lt;/summary&gt;
''' &lt;param name="parametersJson"&gt;
'''  A JSON formatted record (FormInitialisationInfo) object.
''' &lt;/param&gt;
Private Function Finish(parametersJson As String,
                        requestInfo As finScriptRequestInfo,
                        ByRef returnValue As String) As Boolean

  Dim obj As Object
  Dim Record As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Parse Parameters
  If finBL.Runtime.WebUtilities.DeserialiseJsonStringToObject(parametersJson, GetType(FormInitialisationInfo), obj) Then
    Record = DirectCast(obj, FormInitialisationInfo)
  Else
    Success = False
  End If

  ' Get Workflow
  If Success Then
    Success = GetWorkflow()
  End If

  ' Validate
  If Success Then
    If Record.Timestamp &lt;&gt; mWorkflow.Timestamp Then
      Success = False
      finBL.Error.ErrorBegin("This record has been updated by another User.")
    End If
  End If

  ' Update and Save
  ' NOTE: Recheck Permissions in addition to the 'AllowPage' properties before updating to prevent spoofing
  If Success Then
    ' Begin Transaction
    If finBL.Database.TransactionBegin() Then
      ' Update Client
      With mWorkflow
        ' General
        If Record.AllowPageGeneral AndAlso finBL.CurrentUser.Permissions.Allow("Workflow.Form.Page.General") Then
          .WorkflowId = Record.WorkflowId
          .Description = Record.Description

          .FlagColour = Record.FlagColour
          .FlagNotes = Record.FlagNotes
          .ReviewDate = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(Record.ReviewDate)

          .AutoSuspendUntilDate = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(Record.AutoSuspendUntilDate)

          .RecallTzDateSet(finBL.HtmlWidgetUtilities.GetDatabaseDateTimeFromJsonUtcDateTime(Record.RecallTzDate), Record.TimeZoneId)

          .Notes = Record.Notes
        End If

        ' Users
        If Record.AllowPageUsers AndAlso finBL.CurrentUser.Permissions.Allow("Workflow.Form.Page.Users") Then
          .AllocatedUserId = Record.AllocatedUserId
          .PendingAllocatedUserId = Record.PendingAllocatedUserId
          .HoldAllocatedUser = Record.HoldAllocatedUser
        End If

        ' User Defined
      End With

      ' Save
      If Success Then
        Success = mWorkflow.Save()
      End If

      ' Commit/ Rollback Transaction
      If Success Then
        finBL.Database.TransactionCommit()
      Else
        finBL.Database.TransactionRollback()
      End If
    Else
      Success = False
    End If
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Validate a Wizard page.
''' &lt;/summary&gt;
''' &lt;param name="returnValue"&gt;
'''  A JSON object; "true" if validation passed, otherwise, information as to why validation failed.
''' &lt;/param&gt;
Private Function WizardValidate(parametersJson As String,
                                ByRef returnValue As String) As Boolean

  Dim Data As Object
  Dim FailedControlId As String
  Dim FailedMessage As String
  Dim PageId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Get Parameters
  ' NOTE: Use the module mCombinedParameters since this contains Startup and event Parameters in a single Key/Value List
  With mCombinedParameters
    PageId = .GetString("PageId")
  End With

  ' Validate Page
  Select Case PageId
    Case "General"
      ' General
  End Select

  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(New WizardValidateResponse(Data, FailedMessage, FailedControlId), returnValue)
  End If

  Return Success

End Function


''' &lt;summary&gt;
'''  Wizard Initialisation Information.
''' &lt;/summary&gt;
''' &lt;remarks&gt;
'''  This object is also used to save the Employment.
''' &lt;/remarks&gt;
Public Class FormInitialisationInfo

  ' Form
  Public PageId As String
  Public [ReadOnly] As Boolean

  ' Record
  Public Pk As Integer
  Public Timestamp As Integer

  ' General
  Public WorkflowId As String
  Public Description As String
  Public WorkflowTypeId As String
  Public WorkflowTypeDescription As String
  Public WorkflowTypeCategory As String
  Public TargetObjectTypeText As String
  Public TargetObjectId As String
  Public TargetObjectName As String

  Public Status As isefinWorkflowStatus
  Public StatusText As String
  Public FlagColour As String
  Public FlagNotes As String
  Public ReviewDate As Date?

  Public AutoSuspendUntilDate As Date?

  Public TimeZoneId As String
  Public RecallTzDate As Date?
  Public RecallImmediate As Boolean
  Public RecallImmediateDetails As String

  Public Notes As String

  ' Users
  Public AllocatedUserId As String
  Public PendingAllocatedUserId As String
  Public HoldAllocatedUser As Boolean

  ' User Defined

  ' Other
  Public AllocatedUserSqlWhere As String

  ' Permissions
  Public AllowPageGeneral As Boolean
  Public AllowPageUsers As Boolean

  Public CanUpdateRecallDate As Boolean

  ' Lists
  Public FlagColourList As String

  ' Configuration
  Public AddOnBranch As Boolean

  Public HideOtherPages As Boolean
  Public PromptOnSave As Boolean

  ' Other

End Class


''' &lt;summary&gt;
'''  Validation details.
''' &lt;/summary&gt;
Public Class WizardValidateResponse

  Public Data As Object
  Public FailedMessage As String
  Public FailedControlId As String

  Public Sub New(data As Object,
                 failedMessage As String,
                 failedControlId As String)

    Me.Data = data
    Me.FailedMessage = failedMessage
    Me.FailedControlId = failedControlId

  End Sub

End Class</Code>
    <Language>VisualBasic</Language>
    <Notes>System-supplied HTML Widget to edit a Workflow.</Notes>
    <PermissionKeyExecute />
    <RunWithoutPrompts>false</RunWithoutPrompts>
    <TemplateText>&lt;div id="frmMain" class="is-widget-content" style="visibility:hidden"&gt;

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabDetails" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="General"&gt;General&lt;/li&gt;
        &lt;li tabId="Users"&gt;Users&lt;/li&gt;
      &lt;ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;


  &lt;!-- Pages --&gt;
  &lt;div class="is-widget-form-body"&gt;
    &lt;!-- General --&gt;
    &lt;div id="pageGeneral"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCodeAndName"&gt;Code, Description and Workflow Type&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWorkflowId"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWorkflowId"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDescription"&gt;Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDescription"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboWorkflowType"&gt;Type:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboWorkflowType"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWorkflowTypeCategory"&gt;Category:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWorkflowTypeCategory"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboTargetObject"&gt;Target:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboTargetObject"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblStatus"&gt;Workflow Status&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtStatus"&gt;Status:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtStatus"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateReviewDate"&gt;Review Date:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="dateReviewDate"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboFlagColour"&gt;Flag Colour:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboFlagColour"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtFlagNotes"&gt;Flag Notes:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtFlagNotes"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblRecallDetails"&gt;Recall details&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateRecallDate"&gt;Recall Date:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;div id="dateRecallDate"&gt;&lt;/div&gt;&lt;/td&gt;
        &lt;/tr&gt;
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;
            &lt;input id="chkRecallImmediately" type="checkbox" /&gt;
            &lt;button id="cmdRecallImmediatelyDetails" class="is-button small"&gt;Details&lt;/button&gt;
          &lt;/th&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblSuspendAutomaticCreationUntil"&gt;Suspend automatic creation of another Workflow of this Type or Category&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateAutoSuspendUntil"&gt;Until:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="dateAutoSuspendUntil"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;th colspan="2"&gt;&lt;label id="lblNotes"&gt;Notes&lt;/label&gt;&lt;/th&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="txtNotes" /&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
      
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Users --&gt;
    &lt;div id="pageUsers"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:10em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblAllocatedUser"&gt;Allocated User&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboAllocatedUser"&gt;Current:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboAllocatedUser"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboPendingAllocatedUser"&gt;Pending:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboPendingAllocatedUser"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkHoldAllocatedUser" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;

  &lt;/div&gt;


  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdCancel" class="is-button"&gt;Cancel&lt;/button&gt;
    &lt;button id="cmdFinish" class="is-button ok"&gt;Save&lt;/button&gt;
  &lt;/footer&gt;

&lt;/div&gt;


&lt;script&gt;
// Properties
var mRecord;

// Controls
var C = {
  //   General
  lblCodeAndName: null,
  txtWorkflowId: null,
  txtDescription: null,
  cboWorkflowType: null,
  txtWorkflowTypeCategory: null,
  cboTargetObject: null,

  lblStatus: null,
  txtStatus: null,
  dateReviewDate: null,
  cboFlagColour: null,
  txtFlagNotes: null,

  lblRecallDetails: null,
  dateRecallDate: null,
  chkRecallImmediately: null,

  lblSuspendAutomaticCreationUntil: null,
  dateAutoSuspendUntil: null,

  lblNotes: null,
  txtNotes: null,

  //   Users
  lblAllocatedUser: null,
  cboAllocatedUser: null,
  cboPendingAllocatedUser: null,
  chkHoldAllocatedUser: null,

  //   User Defined
}

// Form
var frmMain;
var tabDetails;

// Buttons
var cmdCancel;
var cmdFinish;

var cmdRecallImmediatelyDetails;

// Other

// ==========
// Initialise
// ==========
$(function () {
  // Mobile optimisations
  $(window).resize(Form_Resize);

  // --------
  // Controls
  // --------
  //   General
  C.lblCodeAndName = widget.UI.Label("lblCodeAndName", {});
  C.txtWorkflowId = widget.UI.TextBox("txtWorkflowId", {
    allowBlank: false,
    maxLength: 10,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.txtDescription = widget.UI.TextBox("txtDescription", {
    allowBlank: false,
    maxLength: 50,
  });
  C.cboWorkflowType = widget.UI.DBCombo("cboWorkflowType", {
    autoReadOnly: false,
    readOnly: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.txtWorkflowTypeCategory = widget.UI.TextBox("txtWorkflowTypeCategory", {
    autoReadOnly: false,
    readOnly: true,
    maxLength: 50,
  });
  C.cboTargetObject = widget.UI.DBCombo("cboTargetObject", {
    autoReadOnly: false,
    readOnly: true,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  C.lblStatus = widget.UI.Label("lblStatus", {});
  C.txtStatus = widget.UI.TextBox("txtStatus", {
    autoReadOnly: true,
    readOnly: true,
    width: "12em",
  });
  C.dateReviewDate = widget.UI.DateBox("dateReviewDate", {});
  C.cboFlagColour = widget.UI.IconComboBox("cboFlagColour", {
    iconPrefix: "Flag[",
    iconSuffix: "]",
    limitToList: true,
    width: "12em",
  });
  C.txtFlagNotes = widget.UI.TextBox("txtFlagNotes", {
    maxLength: 255,
    multiLine: true,
    rows: 2,
  });

  C.lblRecallDetails = widget.UI.Label("lblRecallDetails", {
    tooltipText: "Once the Recall Date is reached (or Recall Immediately is checked), this Workflow will be brought to the User's attention in the Task Manager.",
  });
  C.dateRecallDate = widget.UI.DateTimeZone("dateRecallDate", {
    timeZoneVisible: true,
  });
  C.chkRecallImmediately = widget.UI.CheckBox("chkRecallImmediately", {
    readOnly: true,
    caption: "Recall immediately?",
  });

  C.lblSuspendAutomaticCreationUntil = widget.UI.Label("lblSuspendAutomaticCreationUntil", {
    tooltipText: "Suspending automatic Workflow creation will prevent rules (e.g. Account Rules) from starting another Workflow of this Type or Category until the specified date is met. This is only applied if the Workflow Type is configured to disallow multiple 'Open' Workflows or this Type or Category.",
  });
  C.dateAutoSuspendUntil = widget.UI.DateBox("dateAutoSuspendUntil", {});

  C.lblNotes = widget.UI.Label("lblNotes", {});
  C.txtNotes = widget.UI.TextBox("txtNotes", {
    maxLength: 32767,
    multiLine: true,
    rows: 8,
  });

  C.lblAllocatedUser = widget.UI.Label("lblAllocatedUser", {});
  C.cboAllocatedUser = widget.UI.DBCombo("cboAllocatedUser", {
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.cboPendingAllocatedUser = widget.UI.DBCombo("cboPendingAllocatedUser", {
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.chkHoldAllocatedUser = widget.UI.CheckBox("chkHoldAllocatedUser", {
    caption: "Hold the currently Allocated User?",
  });

  //   Users
  C.lblBranch = widget.UI.Label("lblBranch", {});

  // Create Widget form
  // NOTE: Hide by default for a cleaner startup
  frmMain = new widget.UI.Form("frmMain", { visible: false });

  // Create Tabs
  tabDetails = new widget.UI.Tabs("tabDetails", {
    style: "normal",
    onSelectedTabChanged: tabDetails_Refresh,
  });

  // Handle resize
  $(window).resize(Form_Resize);

  // Handle Wizard Buttons
  cmdCancel = $("#cmdCancel");
  cmdFinish = $("#cmdFinish");
  cmdCancel.click(tabDetails_Cancel);
  cmdFinish.click(Form_ExecuteAction_Finish);

  cmdRecallImmediatelyDetails = $("#cmdRecallImmediatelyDetails");
  cmdRecallImmediatelyDetails.click(RecallImmediatelyDetails);

  // Reset
  Form_Reset();
});

// ==========
// Reset Form
// ==========
function Form_Reset() {
  // Resize
  Form_Resize();

  // Load Record (i.e., initialise wizard)
  Record_Load();
}

// ===========
// Load Record
// ===========
function Record_Load() {
  // Initialise
  mRecord = null;

  // Hide content
  frmMain.Visible(false);

  // Block UI
  widget.UI.Block("Initialising, please wait...");

  // Load Initialisation details
  widget.GetString("GetInitialisationInfo", {},
    // Success
    Record_Load_Done,

    // Fail
    function (message) {
      widget.UI.MsgBoxAlert("fail: " + message);
      Fields_Load();
    }
  );
}

function Record_Load_Done(data) {
  // Initialise
  mRecord = JSON.parse(data);

  // Set Tab
  if (mRecord &amp;&amp; mRecord.PageId) {
    tabDetails.SelectedTabId(mRecord.PageId);

    // Hide other Pages
    if (mRecord.HideOtherPages) {
      tabDetails.ShowSingleTab(mRecord.PageId);
    }

    // Page Permissions
    if (!mRecord.AllowPageGeneral) tabDetails.TabVisible("General", false);
    if (!mRecord.AllowPageUsers) tabDetails.TabVisible("Users", false);
  }
  else {
    tabDetails.SelectedTabId("General");
  }

  // Load Fields
  Fields_Load();
}

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.txtWorkflowId.Text(mRecord.WorkflowId);
    C.txtDescription.Text(mRecord.Description);
    C.cboWorkflowType.RefreshUnbound(mRecord.WorkflowTypeId, mRecord.WorkflowTypeDescription);
    C.txtWorkflowTypeCategory.Text(mRecord.WorkflowTypeCategory);
    C.cboTargetObject.RefreshUnbound(mRecord.TargetObjectId, mRecord.TargetObjectName);

    C.txtStatus.Text(mRecord.StatusText);
    C.dateReviewDate.Value(mRecord.ReviewDate);
    C.cboFlagColour.Text(mRecord.FlagColour);
    C.txtFlagNotes.Text(mRecord.FlagNotes);

    C.dateAutoSuspendUntil.Value(mRecord.AutoSuspendUntilDate);

    C.dateRecallDate.TimeZoneId(mRecord.TimeZoneId);
    C.dateRecallDate.Value(mRecord.RecallTzDate);
    C.chkRecallImmediately.Value(mRecord.RecallImmediate);

    C.txtNotes.Text(mRecord.Notes);

    // Users
    C.cboAllocatedUser.Text(mRecord.AllocatedUserId);
    C.cboPendingAllocatedUser.Text(mRecord.PendingAllocatedUserId);
    C.chkHoldAllocatedUser.Value(mRecord.HoldAllocatedUser);

    // User Defined
  }

  // Unblock UI
  widget.UI.Unblock();

  // Update Controls

  // Update fields
  Fields_Update();

  // Refresh Tab
  tabDetails_Refresh();
  tabDetails_Resize();
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  mRecord.WorkflowId = C.txtWorkflowId.Text();
  mRecord.Description = C.txtDescription.Text();

  mRecord.ReviewDate = C.dateReviewDate.Value();
  mRecord.FlagColour = C.cboFlagColour.Text();
  mRecord.FlagNotes = C.txtFlagNotes.Text();

  mRecord.AutoSuspendUntilDate = C.dateAutoSuspendUntil.Value();

  mRecord.TimeZoneId = C.dateRecallDate.TimeZoneId();
  mRecord.RecallTzDate = C.dateRecallDate.Value();

  mRecord.Notes = C.txtNotes.Text();

  // Users
  mRecord.AllocatedUserId = C.cboAllocatedUser.Text();
  mRecord.PendingAllocatedUserId = C.cboPendingAllocatedUser.Text();
  mRecord.HoldAllocatedUser = C.chkHoldAllocatedUser.Value();

  // User Defined
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    widget.SetHeading("Workflow (" + mRecord.WorkflowId + ")");
  }

  // Information Lists
  if (mRecord) {
 }

  // Lists
  if (mRecord) {
    C.cboFlagColour.ListFromCsvString(mRecord.FlagColourList);

    C.cboAllocatedUser.RefreshFromStandardRange("Users", mRecord.AllocatedUserSqlWhere);
    C.cboPendingAllocatedUser.RefreshFromStandardRange("Users", mRecord.AllocatedUserSqlWhere);
  }

  // Controls
  if (mRecord) {
    C.cboTargetObject.Caption(mRecord.TargetObjectTypeText + ":");
    C.dateRecallDate.ReadOnly(!mRecord.CanUpdateRecallDate);

    if (!mRecord.RecallImmediate) cmdRecallImmediatelyDetails.hide();
  }

  // Pages
  if (mRecord) {
    // NOTE: Even though many pages are updated in tabDetails_Refresh, we must update them here to ensure controls are hidden since this is not a wizard and all pages are validated on "Finish"
    pageGeneral_Refresh();
    pageUsers_Refresh();
  }

  // Read-Only?
  if (mRecord &amp;&amp; mRecord.ReadOnly) {
    cmdFinish.prop("disabled", true);
    frmMain.FormReadOnly(C, true);
  }

  // Show content
  frmMain.Visible(mRecord != null);

  // Resize Tab
  tabDetails_Resize();
}

// ===========
// Resize Form
// ===========
function Form_Resize() {
  // Mobile Optimisations
  var el = $(".mobile-indent th.indent1, .mobile-indent th.no-indent1");
  if (window.innerWidth &lt; 500) {
    el.addClass("no-indent1").removeClass("indent1");
  }
  else {
    el.addClass("indent1").removeClass("no-indent1");
  }

  // General

  // Tab
  tabDetails_Resize();
}

// ==============
// Wizard Buttons
// ==============
function tabDetails_Cancel() {
  if (widget.CanClose()) {
    widget.Close();
  }
  else {
    widget.Reset();
  }
}

// ==========
// Resize Tab
// ==========
function tabDetails_Resize() {
  switch (tabDetails.SelectedTabId()) {
    case "General":
      // General
      C.txtDescription.WidthResizeFromParent();
      C.cboWorkflowType.WidthResizeFromParent();
      C.txtWorkflowTypeCategory.WidthResizeFromParent();

      C.txtNotes.WidthResizeFromParent();
      break;

    case "Users":
      // Users
      break;
  }
}

// ===========
// Refresh Tab
// ===========
function tabDetails_Refresh() {
   // Load details
  switch (tabDetails.SelectedTabId()) {
    case "General":
      pageGeneral_Refresh();
      break;

    case "Users":
      pageUsers_Refresh();
      break;

    default:
      break;
  }

  // Resize
  tabDetails_Resize();

  // Focus
  switch (tabDetails.SelectedTabId()) {
    default:
      tabDetails.FocusFirst();
      break;
  }
}

// =================
// Execute an Action
// =================
function Form_ExecuteAction(actionId, data) {
  switch(actionId) {
    default:
      window.alert("Unhandled action '" + actionId + "'");
  }
}

// =============
// Finish Action
// =============
function Form_ExecuteAction_Finish() {
  // Assume Success
  var Ok = true;

  // Validate
  Ok = tabDetails.Validate();

  // Prompt
  if (Ok) {
    if (mRecord.PromptOnSave) {
      // Confirm
      widget.UI.MsgBoxConfirm("Are you sure you want to save this record?",
                              { heading: "Save" },
                              Form_ExecuteAction_FinishPost);

    }
    else {
      // Save without prompting
      Form_ExecuteAction_FinishPost();
    }
  }
}

function Form_ExecuteAction_FinishPost() {
  // Disable Form
  widget.UI.Block("Saving, please wait...");

  // Create Parameters
  // NOTE: We will simply update mRecord, clone this and send back (less some information)
  Fields_Save();
  var params = JSON.parse(JSON.stringify(mRecord));
  //params.GendersList = null;

  // Finish
  widget.GetString("Finish", params,
    function (data) {
      // Close Form
      widget.Close();

      // Refresh Parent (to show updated details)
      // NOTE: Pass in Account Id just in case this has changed
      widget.RefreshParent(C.txtWorkflowId.Text());
    },

    function (data) {
      // Show Error
      widget.UI.MsgBoxAlert(data);

      // Enable Form
      widget.UI.Unblock();
    }
  );
}

// ===========
// pageGeneral
// ===========
function pageGeneral_Refresh() {
  if (!mRecord) return;

  // Controls
  C.txtWorkflowTypeCategory.VisibleRow(mRecord.WorkflowTypeCategory != "");

  // Hide all
  C.dateReviewDate.VisibleRow(false);
  C.dateAutoSuspendUntil.VisibleRow(false);
  C.lblSuspendAutomaticCreationUntil.VisibleRow(false);
  C.lblRecallDetails.VisibleRow(false);
  C.dateRecallDate.VisibleRow(false);
  C.chkRecallImmediately.VisibleRow(false);

  switch(mRecord.Status) {
    case "Closed":
      C.lblSuspendAutomaticCreationUntil.VisibleRow(true);
      C.dateAutoSuspendUntil.VisibleRow(true);
      break;

    case "OnHold":
      C.dateReviewDate.VisibleRow(true);
      C.lblRecallDetails.VisibleRow(true);
      C.dateRecallDate.VisibleRow(true);
      C.chkRecallImmediately.VisibleRow(true);
      break;

    case "Open":
    case "Pending":
      C.lblRecallDetails.VisibleRow(true);
      C.dateRecallDate.VisibleRow(true);
      C.chkRecallImmediately.VisibleRow(true);
      break;

    default:
      window.alert("Unhandled Status '" + mRecord.Status + "'.");
  }
}

// =========
// pageUsers
// =========
function pageUsers_Refresh() {
  if (!mRecord) return;

  // Controls
}

// ==============
// Recall Actions
// ==============
function RecallImmediatelyDetails() {
  widget.UI.MsgBoxInfo(mRecord.RecallImmediateDetails);
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>60</TimeoutSeconds>
    <UniqueId>wP4C87ON202fQIuatidZiQ</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption>Workflow</Caption>
    <HtmlWidgetMaxHeight>800</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <Icon />
    <RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled>
    <RunAsAdministrator>false</RunAsAdministrator>
    <WebServiceName />
    <WebServiceAllowAnonymous>false</WebServiceAllowAnonymous>
    <WebServiceSendDebugInformation>false</WebServiceSendDebugInformation>
    <ShowInMenu>None</ShowInMenu>
    <ParametersType>Custom</ParametersType>
    <Parameters>
      <ISParameterDefs version="1.00">
        <Parameters>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Form options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="HideOtherPages" type="Boolean">
            <BlankTip />
            <Caption>Hide pages other than the one being edited?</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>True</Value>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Configuration options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>TESTING</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="WorkflowId" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <List>RANGE.Workflows</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="Page" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <List>General,Details,UserDefined</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ReadOnly" type="Boolean">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>False</Value>
            <Visible>true</Visible>
          </Parameter>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>