<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2024-08-28T04:54:11.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2021-02-09T20:45:45.8370000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2024-08-28T04:53:32.1570000</UpdatedUtcDate>
    <ScriptId>OUTCOMMS</ScriptId>
    <Description>Outgoing Communication Html Widget</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_OutgoingCommunication
Option Explicit On
Option Strict On

' #################################################################
' Outgoing Communication wizard
'
' Version: 1.08 (28/08/2024)
'
' Usage: System-defined HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  15/02/2021  ISS                Created
'    1.01  29/10/2021  ISS      J027638   Record &amp; Target optional if Workflow provided
'    1.02  28/03/2022  ISS      J028484   Added more information to "Contacted At" Combo Box
'          12/04/2022  ISS      J028485   "Contacted" list now includes NOK
'    1.03  15/06/2022  ISS      J028750   "Call" button now available for phone numbers
'    1.04  22/09/2022  ISS      J028948   Updated "Contacted" to use new GetMessagingContactNames functions
'    1.05  10/10/2023  ISS      J032106   File Name added and Outcome list is now sectioned
'          26/10/2023  ISS      J032248   Added support for setting defaults for Workflow Items of type "Outgoing Communication"
'    1.06  01/03/2024  ISS      J032824   "Contacted" list is now sorted by Account Clients first
'    1.07  25/06/2024  ISS      J033766   Added widget parameters to send to GetMessagingContactNames()
'    1.08  28/08/2024  ISS      J034176   Improved cboContactedAt_Change Change Event
' #################################################################

' Constants
Private Const FORM_KEY As String = "OutgoingCommunication"

' Common Parameters
Private mIncludeBroker As Boolean = True
Private mIncludeDealer As Boolean = True
Private mIncludeEmail As Boolean = True
Private mIncludeEmployees As Boolean = True
Private mIncludeEmployments As Boolean = True
Private mIncludeFax As Boolean = True
Private mIncludeGuarantors As Boolean = True
Private mIncludeInsurer As Boolean = True
Private mIncludeManagerAccount As Boolean = True
Private mIncludeManagerClient As Boolean = True
Private mIncludeName As Boolean = True
Private mIncludeOther As Boolean = True
Private mIncludeOtherContactMethods As Boolean = True
Private mIncludeOtherRoles As Boolean = True
Private mIncludePhone As Boolean = True
Private mIncludeSms As Boolean = True
Private mRecordId As String
Private mReplyLogPk As Integer
Private mTarget As isefinWorkflowTargetObjectType
Private mWorkflowPk As Integer
Private mWorkflowItemPk As Integer

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

' Other
Private mHostingContext As isefinHtmlWidgetHostingContext

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

  ' Initialise
  mHostingContext = hostingContext

  ' 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 Common Parameters
  With mCombinedParameters
    mIncludeBroker = .GetBoolean("IncludeBroker", mIncludeBroker)
    mIncludeDealer = .GetBoolean("IncludeDealer", mIncludeDealer)
    mIncludeEmail = .GetBoolean("IncludeEmail", mIncludeEmail)
    mIncludeEmployees = .GetBoolean("IncludeEmployees", mIncludeEmployees)
    mIncludeEmployments = .GetBoolean("IncludeEmployments", mIncludeEmployments)
    mIncludeFax = .GetBoolean("IncludeFax", mIncludeFax)
    mIncludeGuarantors = .GetBoolean("IncludeGuarantors", mIncludeGuarantors)
    mIncludeInsurer = .GetBoolean("IncludeInsurer", mIncludeInsurer)
    mIncludeManagerAccount = .GetBoolean("IncludeManagerAccount", mIncludeManagerAccount)
    mIncludeManagerClient = .GetBoolean("IncludeManagerClient", mIncludeManagerClient)
    mIncludeManagerClient = .GetBoolean("IncludeManagerClient", mIncludeManagerClient)
    mIncludeName = .GetBoolean("IncludeName", mIncludeName)
    mIncludeOther = .GetBoolean("IncludeOther", mIncludeOther)
    mIncludeOtherContactMethods = .GetBoolean("IncludeOtherContactMethods", mIncludeOtherContactMethods)
    mIncludeOtherRoles = .GetBoolean("IncludeOtherRoles", mIncludeOtherRoles)
    mIncludePhone = .GetBoolean("IncludePhone", mIncludePhone)
    mIncludeSms = .GetBoolean("IncludeSms", mIncludeSms)
    mRecordId = .GetString("Id")
    mReplyLogPk = .GetInteger("ReplyLogPk")
    mTarget = DirectCast(.GetEnum("Type", GetType(isefinWorkflowTargetObjectType)), isefinWorkflowTargetObjectType)
    mWorkflowPk = .GetInteger("WorkflowPk")
    mWorkflowItemPk = .GetInteger("WorkflowItemPk")
  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
      Main = Finish(parametersJson, requestInfo, returnValue)

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

    Case "IsPhoneNumber"
      ' Determines if the supplied Contact is a phone number
      Main = IsPhoneNumber(returnValue)

    Case "WizardValidate"
      ' Validate wizard page
      Main = WizardValidate(parametersJson, returnValue)

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

End Function

''' &lt;summary&gt;
'''  Create Log and return as Interface.
''' &lt;/summary&gt;
Private Function CreateGenericLog(ByRef log As I_finLog,
                                  target As isefinWorkflowTargetObjectType,
                                  wizardFinishParameters As WizardFinishParameters) As Boolean

  Dim AccountAppLog As finAccountAppLog
  Dim AccountLog As finAccountLog
  Dim ClientLog As finClientLog
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef Parameters
  log = Nothing

  ' Create Log
  If Success Then
    Select Case target
      Case isefinWorkflowTargetObjectType.Account
        ' Account Log
        AccountLog = finBL.CreateAccountLog()
        With AccountLog
          .AccountId = wizardFinishParameters.RecordId

          ' Set Account Balance etc
          Success = .AccountDataSet()

          ' Fee
          If Success AndAlso wizardFinishParameters.FeeCharge Then
            .ChargeFee = True
            .Fee = wizardFinishParameters.FeeValue
            .FeeElementId = wizardFinishParameters.FeeElement
            .FeeNotes = wizardFinishParameters.FeeNotes
            .FeeReference = wizardFinishParameters.FeeReference
          End If
        End With
        log = AccountLog

      Case isefinWorkflowTargetObjectType.AccountApp
        ' Account App Log
        AccountAppLog = finBL.CreateAccountAppLog()
        With AccountAppLog
          .AccountAppId = wizardFinishParameters.RecordId
        End With
        log = AccountAppLog

      Case isefinWorkflowTargetObjectType.Client
        ' Client Log
        ClientLog = finBL.CreateClientLog()
        With ClientLog
          .ClientId = wizardFinishParameters.RecordId
        End With
        log = ClientLog
    End Select
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Finish and create Log.
''' &lt;/summary&gt;
Private Function Finish(parametersJson As String,
                        requestInfo As finScriptRequestInfo,
                        ByRef returnValue As String) As Boolean

  Dim ActionWorkflowItem As Boolean
  Dim DocumentFileNameResolved As String
  Dim Log As I_finLog
  Dim LogObjectType As isefinLogObjectType
  Dim obj As Object
  Dim Success As Boolean
  Dim Target As isefinWorkflowTargetObjectType
  Dim WarningMessage As String
  Dim WizardFinishParameters As WizardFinishParameters
  Dim Workflow As finWorkflow
  Dim WorkflowItem As finWorkflowItem
  Dim WorkflowItemOutcome As String

  ' Assume Success
  Success = True

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

  ' Load Workflow
  If Success Then
    If mWorkflowPk &lt;&gt; 0 AndAlso (mWorkflowItemPk &lt;&gt; 0 OrElse WizardFinishParameters.WorkflowLinkCurrentItem) Then
      Workflow = finBL.CreateWorkflow()
      Success = Workflow.LoadPk(mWorkflowPk)
    End If
  End If

  ' Action Workflow Item?
  If Success Then
    If Workflow IsNot Nothing AndAlso mWorkflowItemPk &lt;&gt; 0 Then
      WorkflowItem = Workflow.GetItemByPk(mWorkflowItemPk)

      ' Determine if the Workflow Item should be actioned and if the Outcome should be included
      If WorkflowItem IsNot Nothing Then
        Select Case WorkflowItem.ItemType
          Case isefinWorkflowItemType.HtmlWidget, isefinWorkflowItemType.HtmlWidgetScript
            ActionWorkflowItem = True
            WorkflowItemOutcome = WizardFinishParameters.Outcome

          Case isefinWorkflowItemType.OutgoingCommunication
            ActionWorkflowItem = True
        End Select
      End If
    End If
  End If

  ' Link to the current Workflow Item?
  If Success AndAlso Workflow IsNot Nothing AndAlso WizardFinishParameters.WorkflowLinkCurrentItem Then
    WorkflowItem = Workflow.GetCurrentItem()
    If WorkflowItem IsNot Nothing Then mWorkflowItemPk = WorkflowItem.Pk
  End If

  ' Set Target
  If Success Then
    Success = [Enum].TryParse(Of isefinWorkflowTargetObjectType)(wizardFinishParameters.Target, Target)
  End If 
  
  ' Create Log
  If Success Then
    Success = CreateGenericLog(Log, Target, WizardFinishParameters)
  End If

  ' Upload file to Document Manager?
  If Success AndAlso requestInfo.Files.Count &lt;&gt; 0 Then
    Select Case Target
      Case isefinWorkflowTargetObjectType.Account : LogObjectType = isefinLogObjectType.Account
      Case isefinWorkflowTargetObjectType.AccountApp : LogObjectType = isefinLogObjectType.AccountApp
      Case isefinWorkflowTargetObjectType.Client : LogObjectType = isefinLogObjectType.Client
    End Select
    Success = finBL.LogUtilities.DocumentFileAdd(LogObjectType, wizardFinishParameters.RecordId, requestInfo.Files(0).FileData, requestInfo.Files(0).FileName, True, DocumentFileNameResolved)
  End If
  
  ' Populate Log
  If Success Then
    With Log
      ' General
      .LogTimeZoneId = WizardFinishParameters.LogDateTimeZoneId
      .LogTzDate = finBL.HtmlWidgetUtilities.GetDatabaseDateTimeFromJsonUtcDateTime(WizardFinishParameters.LogTzDate)
      .LogOutcome = WizardFinishParameters.Outcome
      .Subject = WizardFinishParameters.Subject

      .Notes = "Outgoing communication to " &amp; WizardFinishParameters.Contacted
      If Len(WizardFinishParameters.ContactedAt) &lt;&gt; 0 Then .Notes &amp;= " at " &amp; WizardFinishParameters.ContactedAt
      .Notes &amp;= vbNewLine &amp; vbNewLine &amp; WizardFinishParameters.Notes

      .OwnerUserId = finBL.CurrentUser.UserId

      ' Document
      .DocumentFileName = DocumentFileNameResolved
      
      ' Action
      .ActionTimeZoneId = WizardFinishParameters.ActionTimeZoneId
      .ActionTzDate = finBL.HtmlWidgetUtilities.GetDatabaseDateTimeFromJsonUtcDateTime(WizardFinishParameters.ActionTzDate)
      .LogSeverityId = WizardFinishParameters.LogSeverity

      ' Delegated
      .DelegatedToRoleId = WizardFinishParameters.DelegatedRole
      .DelegatedToUserId = WizardFinishParameters.DelegatedUser

      ' Workflow
      .WorkflowPk = mWorkflowPk
      .WorkflowItemPk = mWorkflowItemPk

      ' Parent Log
      .ParentLogPk = mReplyLogPk

      ' Source
      .SourceSet(isefinLogSource.WorkflowOutgoingCommunicationUserInterface)

      ' Save
      Success = .Save()
    End With
  End If

  ' Action Workflow Item
  If Success AndAlso ActionWorkflowItem Then
    finBL.HtmlWidgetUtilities.WorkflowItemComplete(mStartupParameters, WarningMessage, WorkflowItemOutcome)

    If Len(WarningMessage) &lt;&gt; 0 Then
      WarningMessage = "The Outgoing Communication Log was added successfully, however the Workflow Item could not be actioned due to the following error:" &amp; vbNewLine &amp; vbNewLine &amp; WarningMessage
    End If
  End If

  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(New WizardFinishDetails(WarningMessage), returnValue)
  End If

  Return Success

End Function

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

  Dim Account As finAccount
  Dim AccountApp As finAccountApp
  Dim Client As finClient
  Dim dateTemp As Date
  Dim DefaultSubject As String
  Dim DefaultSubjectInformationList As String
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim MessagingContacts As finMessagingContacts
  Dim Success As Boolean
  Dim Workflow As finWorkflow
  Dim WorkflowItem As finWorkflowItem

  ' Assume Success
  Success = True

  ' Validate
  If Len(mRecordId) = 0 AndAlso mWorkflowPk = 0 AndAlso mWorkflowItemPk = 0 Then
    Success = False
    finBL.Error.ErrorBegin("A Record Id or Workflow Pk must be specified.")
  ElseIf mWorkflowItemPk &lt;&gt; 0 AndAlso mWorkflowPk = 0 Then
    Success = False
    finBL.Error.ErrorBegin("A Workflow Pk must be supplied if a Workflow Item Pk has been specified.")
  End If

  ' Validate Workflow
  If Success AndAlso mWorkflowPk &lt;&gt; 0 Then
    Workflow = finBL.CreateWorkflow()

    If Workflow.LoadPk(mWorkflowPk) Then
      If mWorkflowItemPk &lt;&gt; 0 Then
        If Workflow.GetItemByPk(mWorkflowItemPk) Is Nothing Then
          Success = False
          finBL.Error.ErrorBegin("Invalid Workflow Item Pk.")
        End If
      End If
    Else
      Success = False
    End If

    ' Set Record Id and Target from Workflow if required
    If Success Then
      Select Case Workflow.WorkflowType.TargetObjectType
        Case isefinWorkflowTargetObjectType.Account
          mTarget = isefinWorkflowTargetObjectType.Account
          If Len(mRecordId) = 0 Then mRecordId = Workflow.AccountId

        Case isefinWorkflowTargetObjectType.AccountApp
          mTarget = isefinWorkflowTargetObjectType.AccountApp
          If Len(mRecordId) = 0 Then mRecordId = Workflow.AccountAppId

        Case isefinWorkflowTargetObjectType.Client
          mTarget = isefinWorkflowTargetObjectType.Client
          If Len(mRecordId) = 0 Then mRecordId = Workflow.ClientId
      End Select
    End If
    
    ' Get Default Subject Information
    If Success AndAlso mWorkflowItemPk &lt;&gt; 0 Then
      WorkflowItem = Workflow.GetItemByPk(mWorkflowItemPk)
      WorkflowItem.GetLogSubjectParts(DefaultSubject, DefaultSubjectInformationList)
    End If
  End If

  ' Form Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Record
      .RecordCode = mRecordId
      .Target = mTarget.ToString()
      Select Case mTarget
        Case isefinWorkflowTargetObjectType.Account
          ' Account
          Account = finBL.CreateAccount()
          If Account.Load(mRecordId) Then
            .RecordCaption = "Account"
            .RecordDescription = Account.Name

            ' Fee
            .CanChargeFee = (Account.Status = isefinAccountStatus.Open)

            ' Contact Details
            ' NOTE: Include 'Other' Client contacts such as Next of Kin
            Success = finBL.AccountFunctions.GetMessagingContactNames(
                                                Account, 
                                                MessagingContacts,
                                                mIncludeGuarantors,
                                                mIncludeOtherRoles,
                                                mIncludeEmployees,
                                                mIncludeManagerAccount,
                                                mIncludeDealer,
                                                mIncludeBroker,
                                                mIncludeInsurer,
                                                mIncludeOtherContactMethods)
          Else
            Success = False
          End If

        Case isefinWorkflowTargetObjectType.AccountApp
          ' Account App
          AccountApp = finBL.CreateAccountApp()
          If AccountApp.Load(mRecordId) Then
            .RecordCaption = "Application"
            .RecordDescription = AccountApp.Name

            ' Contact Details
            Success = finBL.AccountAppFunctions.GetMessagingContactNames(
                                                  AccountApp, 
                                                  MessagingContacts,
                                                  mIncludeGuarantors,
                                                  mIncludeOtherRoles,
                                                  mIncludeEmployees,
                                                  mIncludeManagerAccount,
                                                  mIncludeDealer,
                                                  mIncludeBroker)
          Else
            Success = False
          End If

        Case isefinWorkflowTargetObjectType.Client
          ' Client
          Client = finBL.CreateClient()
          If Client.Load(mRecordId) Then
            .RecordCaption = "Client"
            .RecordDescription = Client.Name

            ' Contact Details
            Success = finBL.ClientFunctions.GetMessagingContactNames(
                                              Client, 
                                              MessagingContacts,
                                              mIncludeEmployments,
                                              mIncludeName,
                                              mIncludeEmail,
                                              mIncludeFax,
                                              mIncludePhone,
                                              mIncludeSms,
                                              mIncludeOther,
                                              mIncludeManagerClient)
          Else
            Success = False
          End If

        Case Else
          ' Invalid
          Success = False
          finBL.Error.ErrorBeginFormat("Invalid Type '{0}'", mTarget.ToString())
      End Select

      If Success Then
        ' Workflow
        If mWorkflowPk &lt;&gt; 0 Then
          .WorkflowDescription = finBL.WorkflowFunctions.GetRecordCodeDescription(mWorkflowPk, .WorkflowId)
          .WorkflowItemPk = mWorkflowItemPk
          
          ' Outgoing Communication Workflow Item defaults
          If WorkflowItem IsNot Nothing Then
            If WorkflowItem.ItemType = isefinWorkflowItemType.OutgoingCommunication Then
              .IsOutgoingCommunicationWorkflowItem = True
              
              ' Log Action Period
              If Len(WorkflowItem.LogActionPeriod) &lt;&gt; 0 Then
                Select Case UCase(WorkflowItem.LogActionPeriod)
                  Case "IMMEDIATE"
                    dateTemp = finBL.TimeZoneFunctions.GetCurrentTimeZoneDateTime(finBL.SettingsUser.TimeZoneIdResolved)
                  Case Else
                    dateTemp = finBL.Utilities.DateCycleGetTermEndDate(WorkflowItem.LogActionPeriod, finBL.TimeZoneFunctions.GetCurrentTimeZoneDate(finBL.SettingsUser.TimeZoneIdResolved))
                End Select              
                .OutgoingCommunicationDefaultsActionDate = finBL.HtmlWidgetUtilities.GetNullableJsonUtcDateTimeFromDatabaseDateTime(dateTemp)
              End If              
              
              ' Notes and Log Severity
              .OutgoingCommunicationDefaultsNotes = WorkflowItem.LogNotes
              .OutgoingCommunicationDefaultsLogSeverityId = WorkflowItem.LogSeverityId
              
              ' Delegated
              Select Case WorkflowItem.LogDelegateAction
                Case isefinWorkflowItemLogDelegateAction.Manager
                  ' Delegate to Manager
                  Select Case WorkflowItem.Workflow.WorkflowType.TargetObjectType
                    Case isefinWorkflowTargetObjectType.Account: .OutgoingCommunicationDefaultsDelegatedUserId = WorkflowItem.Workflow.Account.AccountManagerUserId
                    Case isefinWorkflowTargetObjectType.AccountApp: .OutgoingCommunicationDefaultsDelegatedUserId = WorkflowItem.Workflow.AccountApp.AccountManagerUserId
                    Case isefinWorkflowTargetObjectType.Client: .OutgoingCommunicationDefaultsDelegatedUserId = WorkflowItem.Workflow.Client.ClientManagerUserId
                  End Select
                  
                Case isefinWorkflowItemLogDelegateAction.Role
                  ' Delegate to Role
                  .OutgoingCommunicationDefaultsDelegatedRoleId = WorkflowItem.LogDelegateToRoleId
                  
                Case isefinWorkflowItemLogDelegateAction.User
                  ' Delegate to User
                  .OutgoingCommunicationDefaultsDelegatedUserId = WorkflowItem.LogDelegateToUserId
              End Select
            End If
          End If
        End If

        ' Lists
        .FeeElementFilter = finBL.Elements.GetDataViewFilter_ByType(isefinElementType.Fee)
        .MessagingContacts = SortMessagingContacts(MessagingContacts)

        ' Global Collections

        ' Other
        .DefaultTzDate = finBL.HtmlWidgetUtilities.GetJsonUtcDateTimeFromDatabaseDateTime(finBL.TimeZoneFunctions.GetCurrentDatabaseDateTime())
        .DefaultSubject = DefaultSubject        
        If Len(DefaultSubjectInformationList) = 0 Then
          .DefaultSubjectInformationList = "WorkflowOutgoingSubjects"
        Else 
          .DefaultSubjectInformationList = DefaultSubjectInformationList
        End If
        
        ' Configuration
        .OutcomeInformationList = mTarget.ToString() &amp; "LogOutcomes"
        .PromptOnCommit = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnCommit

        ' Advanced Sections
        .ShowDelegated = mCombinedParameters.GetString("ShowDelegated") : If Len(.ShowDelegated) = 0 Then .ShowDelegated = "Advanced"
        .ShowOutcome = mCombinedParameters.GetString("ShowOutcome") : If Len(.ShowOutcome) = 0 Then .ShowOutcome = "Advanced"
        .ShowSeverity = mCombinedParameters.GetString("ShowSeverity") : If Len(.ShowSeverity) = 0 Then .ShowSeverity = "Advanced"
        .ShowDocumentUpload = mCombinedParameters.GetString("ShowDocumentUpload") : If Len(.ShowDocumentUpload) = 0 Then .ShowDocumentUpload = "Advanced"
        
        If finBL.InformationLists.Exists(.OutcomeInformationList) Then
          With finBL.InformationLists(.OutcomeInformationList)
            If .Mandatory AndAlso Len(.DefaultValue) = 0 Then
              FormInitialisationInfo.ShowOutcome = "True"
            End If
          End With
        End If

        .PageGeneralHasAdvanced = (.ShowDelegated = "Advanced" OrElse .ShowOutcome = "Advanced" OrElse .ShowSeverity = "Advanced" OrElse .ShowDocumentUpload = "Advanced")
      End If
    End With

    ' Serialise
    If Success Then
      Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(FormInitialisationInfo, returnValue)
    End If
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Sort Messaging Contacts.
''' &lt;/summary&gt;
Private Function SortMessagingContacts(messagingContacts As finMessagingContacts) As List(Of finMessagingContacts.finJsonMessagingContact)

  Dim JsonMessagingContact As finMessagingContacts.finJsonMessagingContact  
  Dim MessagingContactsJson As New List(Of finMessagingContacts.finJsonMessagingContact)
  
  ' Get Json Object
  For Each JsonMessagingContact In messagingContacts.ToJsonObject()
    If JsonMessagingContact.AccountClientIndex = -1 Then
      MessagingContactsJson.Add(JsonMessagingContact)
    Else 
      MessagingContactsJson.Insert(JsonMessagingContact.AccountClientIndex, JsonMessagingContact)
    End If
  Next 
  
  Return MessagingContactsJson
  
End Function


''' &lt;summary&gt;
'''  Determines if the supplied Contact is a phone number.
''' &lt;/summary&gt;
Private Function IsPhoneNumber(ByRef returnValue As String) As Boolean

  Dim Data As Object
  Dim IsPhone As Boolean
  Dim PhoneNumberDetails As ISPhoneNumberDetails2
  Dim Success As Boolean
  Dim Value As String

  ' Assume Success
  Success = True

  ' Parameters
  With mCombinedParameters
    Value = .GetString("Value")
  End With

  ' Is Phone?
  PhoneNumberDetails = finBL.CurrentCountry.ParsePhoneNumber2(Value)
  If PhoneNumberDetails IsNot Nothing Then
    IsPhone = (Len(PhoneNumberDetails.PhoneNumberResolved) &lt;&gt; 0)
  End If

  ' Json
  Data = New With {
    .IsPhone = IsPhone
  }

  ' Finalise
  Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(Data, returnValue)

  Return Success

End Function

''' &lt;summary&gt;
'''  Validate a Wizard page.
''' &lt;/summary&gt;
''' &lt;param name="parametersJson"&gt;
'''  A JSON formatted object containing information required to validate a Wizard page.
''' &lt;/param&gt;
''' &lt;param name="returnValue"&gt;
'''  A JSON object.
''' &lt;/param&gt;
Private Function WizardValidate(parametersJson As String,
                                ByRef returnValue As String) As Boolean

  Dim ConfirmList As New List(Of String)
  Dim Data As Object
  Dim FailedControlId As String
  Dim FailedMessage As String
  Dim obj As Object
  Dim PageId As String
  Dim Success As Boolean
  Dim WizardFinishParameters As WizardFinishParameters

  ' 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

  ' Parse Parameters
  ' NOTE: parametersJson will always be WizardFinishDetails object for this wizard
  If finBL.Runtime.WebUtilities.DeserialiseJsonStringToObject(parametersJson, GetType(WizardFinishParameters), obj) Then
    WizardFinishParameters = DirectCast(obj, WizardFinishParameters)
  Else
    Success = False
  End If

  ' Validate
  If Success Then
    Select Case PageId
      Case Else
        ' Not Handled
    End Select
  End If

  ' Serialise
  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;
Public Class FormInitialisationInfo

  ' Record
  Public RecordCaption As String
  Public RecordCode As String
  Public RecordDescription As String
  Public Target As String

  ' Workflow
  Public WorkflowId As String
  Public WorkflowDescription As String
  Public WorkflowItemPk As Integer
  Public IsOutgoingCommunicationWorkflowItem As Boolean
  Public OutgoingCommunicationDefaultsActionDate As Date?
  Public OutgoingCommunicationDefaultsNotes As String
  Public OutgoingCommunicationDefaultsLogSeverityId As String
  Public OutgoingCommunicationDefaultsDelegatedRoleId As String
  Public OutgoingCommunicationDefaultsDelegatedUserId As String

  ' Lists
  Public MessagingContacts As New List(Of finMessagingContacts.finJsonMessagingContact)
  Public FeeElementFilter As String

  ' Global Collections

  ' Other
  Public DefaultTzDate As Date
  Public DefaultSubject As String
  Public DefaultSubjectInformationList As String

  ' Advanced Sections
  Public ShowDelegated As String
  Public ShowOutcome As String
  Public ShowSeverity As String
  Public ShowDocumentUpload As String
  Public PageGeneralHasAdvanced As Boolean

  ' Configuration
  Public CanChargeFee As Boolean
  Public OutcomeInformationList As String
  Public PromptOnCommit As Boolean

End Class



''' &lt;summary&gt;
'''  Finish Details.
''' &lt;/summary&gt;
Public Class WizardFinishDetails

  Public WarningMessage As String

  Public Sub New(warningMessage As String)

    With Me
      .WarningMessage = warningMessage
    End With

  End Sub

End Class



''' &lt;summary&gt;
'''  Wizard Finish Parameters.
''' &lt;/summary&gt;
Public Class WizardFinishParameters

  ' Record
  Public RecordId As String
  Public Target As String

  ' Wizard Validation
  Public PageId As String

  ' Workflow
  Public WorkflowLinkCurrentItem As Boolean

  ' Log
  Public ActionTimeZoneId As String
  Public ActionTzDate As Date?
  Public Contacted As String
  Public ContactedAt As String
  Public DelegatedRole As String
  Public DelegatedUser As String
  Public LogTzDate As Date
  Public LogDateTimeZoneId As String
  Public LogSeverity As String
  Public Notes As String
  Public Outcome As String
  Public Subject As String

  ' Fee
  Public FeeCharge As Boolean
  Public FeeElement As String
  Public FeeNotes As String
  Public FeeReference As String
  Public FeeValue As Decimal

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 defined HTML Widget.

Used as a finPOWER Connect Cloud compatible version of the "Outgoing Communication" page from the Workflow Actions form.</Notes>
    <PermissionKeyExecute />
    <ReferenceLinq>false</ReferenceLinq>
    <RunWithoutPrompts>false</RunWithoutPrompts>
    <TemplateText>&lt;div id="frmMain" class="is-widget-content" style="visibility:hidden"&gt;

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;div class="header"&gt;&lt;/div&gt;
    &lt;div class="summary"&gt;&lt;/div&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabWizard" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="General" tooltipText="Enter details about the Outgoing communication."&gt;Outgoing Communication&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;!-- General --&gt;
        &lt;tbody&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblRecord"&gt;Communication details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboRecord"&gt;Type:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboRecord" /&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblWorkflow"&gt;Workflow details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboWorkflow"&gt;Workflow:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboWorkflow" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkWorkflowLinkCurrentItem" type="checkbox"/&gt;&lt;/th&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblDateCommunicationMade"&gt;When was the communication made?&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="dateLogDate"&gt;Date:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;div id="dateLogDate"&gt;&lt;/div&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblWho"&gt;Who was contact made to?&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboContacted"&gt;Contacted:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboContacted" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboContactedAt"&gt;At:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboContactedAt" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;td&gt;&lt;button id="cmdCall" class="is-button icon" icon="ContactMethod_Phone"&gt;Call&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblDetails"&gt;Enter details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboSubject"&gt;Subject:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboSubject" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtNotes"&gt;Notes:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtNotes" /&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblAction"&gt;Specify Action details and Log Severity&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="dateLogActionDate"&gt;Action:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;div id="dateLogActionDate"&gt;&lt;/div&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr advancedId="Severity"&gt;
            &lt;th&gt;&lt;label for="cboLogSeverity"&gt;Severity:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboLogSeverity" /&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr advancedId="Outcome"&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblOutcome"&gt;Specify an Outcome&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr advancedId="Outcome"&gt;
            &lt;th&gt;&lt;label for="cboOutcome"&gt;Outcome:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboOutcome" /&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr advancedId="Delegate"&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblDelegate"&gt;Optionally, specify a User/Role to Delegate to&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr advancedId="Delegate"&gt;
            &lt;th&gt;&lt;label for="cboDelegatedUser"&gt;Delegated:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboDelegatedUser" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr advancedId="Delegate"&gt;
            &lt;th&gt;&lt;label for="cboDelegatedRole"&gt;Role:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboDelegatedRole" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          
          &lt;tr advancedId="DocumentUpload"&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblDocument"&gt;Specify a Document to link to this Log&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr advancedId="DocumentUpload"&gt;
            &lt;th&gt;&lt;label for="cboDocumentFileName"&gt;File Name:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboDocumentFileName"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Fee --&gt;
        &lt;tbody id="tbFee"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblFeeCharge"&gt;Fee&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkFeeCharge" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboFeeElement"&gt;Element:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboFeeElement" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="numFeeValue"&gt;Value:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="numFeeValue" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtFeeReference"&gt;Reference:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtFeeReference" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtFeeNotes"&gt;Notes:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtFeeNotes" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/div&gt;

  &lt;/div&gt;

  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdAdvanced" class="is-button" style="float:left" title="Show/hide advanced options"&gt;Advanced&lt;/button&gt;

    &lt;button id="cmdCancel" class="is-button"&gt;Cancel&lt;/button&gt;
    &lt;button id="cmdBack" class="is-button"&gt;&amp;lt; Back&lt;/button&gt;
    &lt;button id="cmdNext" class="is-button"&gt;Next &amp;gt;&lt;/button&gt;
    &lt;button id="cmdFinish" class="is-button ok"&gt;Finish&lt;/button&gt;
  &lt;/footer&gt;
&lt;/div&gt;

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

// Controls
var C = {
  //   General
  lblRecord: null,
  cboRecord: null,

  lblWorkflow: null,
  cboWorkflow: null,
  chkWorkflowLinkCurrentItem: null,

  lblDateCommunicationMade: null,
  dateLogDate: null,

  lblWho: null,
  cboContacted: null,
  cboContactedAt: null,

  lblDetails: null,
  cboSubject: null,
  txtNotes: null,

  lblAction: null,
  dateLogActionDate: null,
  cboLogSeverity: null,

  lblOutcome: null,
  cboOutcome: null,

  lblDelegate: null,
  cboDelegatedUser: null,
  cboDelegatedRole: null,

  lblDocument: null,
  cboDocumentFileName: null,

  tbFee: null,
  lblFeeCharge: null,
  chkFeeCharge: null,
  cboFeeElement: null,
  numFeeValue: null,
  txtFeeReference: null,
  txtFeeNotes: null,
}

// Form
var frmMain;
var tabWizard;

// Wizard Buttons
var cmdCancel;
var cmdBack;
var cmdNext;
var cmdFinish;

var cmdAdvanced;
var cmdCall;

// Other
var mAdvancedVisible = false;

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

  // Controls
  //   General
  C.lblRecord = widget.UI.Label("lblRecord", {});
  C.cboRecord = widget.UI.DBCombo("cboRecord", {
    allowBlank: true,
    autoReadOnly: false,
    readOnly: true,
    showDropdown: false,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  C.lblWorkflow = widget.UI.Label("lblWorkflow", {
    tooltipText: "By default, the Log created will be linked to this Workflow but not the current Workflow Item.",
  });
  C.cboWorkflow = widget.UI.DBCombo("cboWorkflow", {
    allowBlank: true,
    autoReadOnly: false,
    readOnly: true,
    showDropdown: false,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.chkWorkflowLinkCurrentItem = widget.UI.CheckBox("chkWorkflowLinkCurrentItem", {
    caption: "Link to the current Workflow Item?"
  });

  C.lblDateCommunicationMade = widget.UI.Label("lblDateCommunicationMade", {});
  C.dateLogDate = widget.UI.DateTimeZone("dateLogDate", {
    allowBlank: false,
    timeZoneVisible: true,
  });

  C.lblWho = widget.UI.Label("lblWho", {});
  C.cboContacted = widget.UI.ComboBox("cboContacted", {
    allowBlank: false,
    maxLength: 80,

    onChange: cboContacted_Change,
  });
  C.cboContactedAt = widget.UI.DBCombo("cboContactedAt", {
    maxLength: 50,
    width: "25em",

    onChange: cboContactedAt_Change,
  });

  C.lblDetails = widget.UI.Label("lblDetails", {});
  C.cboSubject = widget.UI.InformationListComboBox("cboSubject", {
    allowBlank: false,
    maxLength: 50,
    
    onChange: cboSubject_Change,
  });
  C.txtNotes = widget.UI.TextBox("txtNotes", {
    multiLine: true,
    rows: 7,
  });

  C.lblAction = widget.UI.Label("lblAction", {});
  C.dateLogActionDate = widget.UI.DateTimeZone("dateLogActionDate", {
    timeZoneVisible: true,
  });
  C.cboLogSeverity = widget.UI.DBCombo("cboLogSeverity", {
    width: widget.UI.FIELD_WIDTH_CODE_5,
  });

  C.lblOutcome = widget.UI.Label("lblOutcome", {});
  C.cboOutcome = widget.UI.InformationListComboBox("cboOutcome", {
    maxLength: 50,
  });

  C.lblDelegate = widget.UI.Label("lblDelegate", {});
  C.cboDelegatedUser = widget.UI.DBCombo("cboDelegatedUser", {
    width: widget.UI.FIELD_WIDTH_CODE_20
  });
  C.cboDelegatedRole = widget.UI.DBCombo("cboDelegatedRole", {
    width: widget.UI.FIELD_WIDTH_CODE_10
  });

  C.lblDocument = widget.UI.Label("lblDocument", {});
  C.cboDocumentFileName = widget.UI.DocumentManagerComboBox("cboDocumentFileName", {
    allowNew: true,    
  });

  C.tbFee = $("#tbFee");
  C.lblFeeCharge = widget.UI.Label("lblFeeCharge", {});
  C.chkFeeCharge = widget.UI.CheckBox("chkFeeCharge", {
    caption: "Charge a Fee to cover expenses?",
    captionWrap: true,

    onChange: chkFeeCharge_Change,
  });
  C.cboFeeElement = widget.UI.DBCombo("cboFeeElement", {
    allowBlank: false,
  });
  C.numFeeValue = widget.UI.NumberBox("numFeeValue", {
    allowBlank: false,
    minValue: 0.01,
  });
  C.txtFeeReference = widget.UI.TextBox("txtFeeReference", {
    allowBlank: false,
    maxLength: 20,
  });
  C.txtFeeNotes = widget.UI.TextBox("txtFeeNotes", {
    maxLength: 255,
  });

  // Grids

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

  // Create Tabs
  tabWizard = new widget.UI.Tabs("tabWizard", { style: "wizard" });

  // Handle Wizard Buttons
  cmdCancel = $("#cmdCancel");
  cmdBack = $("#cmdBack");
  cmdNext = $("#cmdNext");
  cmdFinish = $("#cmdFinish");
  cmdCancel.click(tabWizard_Cancel);
  cmdBack.click(function() { tabWizard_Move(-1); });
  cmdNext.click(function() { tabWizard_Move(1); });
  cmdFinish.click(function() { Form_ExecuteAction("Finish"); });

  cmdAdvanced = $("#cmdAdvanced");
  cmdAdvanced.click(AdvancedToggle);

  cmdCall = $("#cmdCall");
  cmdCall.click(CallPhone);

  // Reset Form
  Form_Reset();
});

// ==========
// Form Reset
// ==========
function Form_Reset() {
  // Defaults

  // Set Tab
  tabWizard.SelectedTabId("General");

  // Resize
  Form_Resize();

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

// ===========
// Record Load
// ===========
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
    function (data) {
      mRecord = JSON.parse(data);

      // Global Collections

      // Give Collections ability to lookup by code

      // Load Fields
      Fields_Load();
    },

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

// ===========
// Fields Load
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.cboRecord.Caption(mRecord.RecordCaption + ":");
    C.cboRecord.RefreshUnbound(mRecord.RecordCode, mRecord.RecordDescription);

    C.cboWorkflow.RefreshUnbound(mRecord.WorkflowId, mRecord.WorkflowDescription);

    C.dateLogDate.Value(mRecord.DefaultTzDate);
    
    C.cboSubject.Text(mRecord.DefaultSubject);
    
    // Outgoing Communication Workflow Item
    if (mRecord.IsOutgoingCommunicationWorkflowItem) {
      C.txtNotes.Text(mRecord.OutgoingCommunicationDefaultsNotes);
      C.dateLogActionDate.Value(mRecord.OutgoingCommunicationDefaultsActionDate);
      C.cboLogSeverity.Text(mRecord.OutgoingCommunicationDefaultsLogSeverityId);
      C.cboDelegatedRole.Text(mRecord.OutgoingCommunicationDefaultsDelegatedRoleId);
      C.cboDelegatedUser.Text(mRecord.OutgoingCommunicationDefaultsDelegatedUserId);
    }    
  }

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

  // Update fields
  Fields_Update();

  // Refresh Tab
  tabWizard_Refresh(0);
}

// ============
// cboContacted
// ============
function cboContacted_Change(sender, e) {
  var newList = [];

  // Handled
  if (e) e.ChangeHandled = true;

  // Reset List
  C.cboContactedAt.ListFromCsvString("");

  // Update 'Contacted At' list
  if (C.cboContacted.Text()) {
    for (var i = 0; i &lt; mRecord.MessagingContacts.length; i++) {
      var item = mRecord.MessagingContacts[i];

      if (item.SourceNameAndDescription == C.cboContacted.Text() &amp;&amp; (item.Value != "*")) {
        newList.push(item);
      }
    }

    // Set list
    C.cboContactedAt.RefreshFromCollection(newList, "Value", "Description", "Source,Name,Role,Description,Value");
  }

  // Update Controls
  cboContactedAt_Change();
}

// ==============
// cboContactedAt
// ==============
function cboContactedAt_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Phone Dialer link
  var found = false;

  // Hide
  cmdCall.hide();

  if (C.cboContactedAt.Text()) {
    // Determine if the Contact is available in the drop down list
    for (var i = 0; i &lt; mRecord.MessagingContacts.length; i++) {
      var item = mRecord.MessagingContacts[i];

      if (item.Value == C.cboContactedAt.Text()) {
        if (item.ContactMethodIsPhone) {
          found = true;
          cmdCall.show();
        }      
        break;
      }
    }

    // Check entered phone number server-side
    if (!found) {
      var params = {
        value: C.cboContactedAt.Text(),
      }

      widget.GetString("IsPhoneNumber", params, function(data) {
        // Parse
        if (data) data = JSON.parse(data);
        if (data.IsPhone) cmdCall.show();
      });
    }
  }
}

// ==========
// cboSubject
// ==========
function cboSubject_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;
  
  // Update Outcome Information List
  C.cboOutcome.SetLogOutcomeComboFromSectionedInformationList(mRecord.OutcomeInformationList, C.cboSubject.Text(), null, null);
}

// ============
// chkFeeCharge
// ============
function chkFeeCharge_Change() {
  C.cboFeeElement.VisibleRow(C.chkFeeCharge.Value());
  C.numFeeValue.VisibleRow(C.chkFeeCharge.Value());
  C.txtFeeReference.VisibleRow(C.chkFeeCharge.Value());
  C.txtFeeNotes.VisibleRow(C.chkFeeCharge.Value());
}

// ========================
// Create Finish Parameters
// ========================
function CreateFinishParameters() {
  var params = {
    recordId: mRecord.RecordCode,
    target: mRecord.Target,

    workflowLinkCurrentItem: C.chkWorkflowLinkCurrentItem.Value(),

    logDateTimeZoneId: C.dateLogDate.TimeZoneId(),
    logTzDate: C.dateLogDate.Value(),
    contacted: C.cboContacted.Text(),
    contactedAt: C.cboContactedAt.Text(),

    subject: C.cboSubject.Text(),
    notes: C.txtNotes.Text(),

    actionTimeZoneId: C.dateLogActionDate.TimeZoneId(),
    actionTzDate: C.dateLogActionDate.Value(),
    logSeverity: C.cboLogSeverity.Text(),

    outcome: C.cboOutcome.Text(),

    delegatedUser: C.cboDelegatedUser.Text(),
    delegatedRole: C.cboDelegatedRole.Text(),

    feeCharge: C.chkFeeCharge.Value(),
    feeElement: C.cboFeeElement.Text(),
    feeValue: C.numFeeValue.Value(),
    feeReference: C.txtFeeReference.Text(),
    feeNotes: C.txtFeeNotes.Text(),
  }

  return params;
}

// =============
// Fields Update
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
  }

  // Information Lists
  if (mRecord) {
    C.cboSubject.SetComboFromInformationList(mRecord.DefaultSubjectInformationList, false, cboSubject_Change, true);    
  }

  // Lists
  if (mRecord) {
    C.cboLogSeverity.RefreshFromStandardRange("LogSeverities");
    C.cboDelegatedUser.RefreshFromStandardRange("UsersCurrentActive");
    C.cboDelegatedRole.RefreshFromStandardRange("Roles");
    C.cboFeeElement.RefreshFromStandardRange("Elements", mRecord.FeeElementFilter);

    // Contact Info
    var list = [];
    for (var i = 0; i &lt; mRecord.MessagingContacts.length; i++) {
      var strTemp = mRecord.MessagingContacts[i].SourceNameAndDescription;

      // Add distinct items to list
      if (!list.includes(strTemp)) list.push(strTemp);
    }
    C.cboContacted.ListFromArray(list);
  }

  // Controls
  if (mRecord) {
    if (!mRecord.WorkflowId) {
      C.lblWorkflow.VisibleRow(false);
      C.cboWorkflow.VisibleRow(false);
      C.chkWorkflowLinkCurrentItem.VisibleRow(false);
    }
    else if(mRecord.WorkflowItemPk) {
      // Workflow Item specified so don't give option to link to current
      C.chkWorkflowLinkCurrentItem.VisibleRow(false);
    }

    // Contacted
    cboContacted_Change();

    // Fee
    if (mRecord.CanChargeFee) {
      chkFeeCharge_Change();
    }
    else {
      C.tbFee.hide();
    }

    // Document Manager
    C.cboDocumentFileName.Refresh(mRecord.Target, mRecord.RecordCode);

    // Initialise Advanced
    AdvancedInitialise();
  }

  // Update Buttons
  tabWizard_UpdateButtons();

  // Set default Advanced headings
  AdvancedToggle_General();

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

  // Resize Tab
  tabWizard_Resize();
}

// =================
// Execute an Action
// =================
function Form_ExecuteAction(actionId) {
  switch (actionId.toUpperCase()) {
    case "FINISH":
      // Finish
      Form_ExecuteAction_Finish(true);
      break;

    default:
      window.alert(mViewName + ".Form_ExecuteAction: Unhandled action '" + actionId + "'");
      break;
  }
}

function Form_ExecuteAction_Finish(publish) {
  // Validate
  tabWizard_Validate(function() {
    if (mRecord.PromptOnCommit || (C.chkFeeCharge.Value() &amp;&amp; C.numFeeValue.Value() != 0)) {
      // Confirm
      var heading = "Create Log";
      var message = "&lt;p&gt;Are you sure you want to create this Outgoing Communication Log?&lt;/p&gt;";

      if (C.chkFeeCharge.Value() &amp;&amp; C.numFeeValue.Value() != 0) {
        message += "&lt;p&gt;NOTE: A fee of &lt;b&gt;" + widget.FormatCurrency(C.numFeeValue.Value(), true) + "&lt;/b&gt; will be charged.&lt;/p&gt;";
      }

      widget.UI.MsgBoxConfirm(message,
                              {
                                heading: heading,
                                icon: "Communication_Outgoing",
                                messageIsHtml: true,
                              },

                              function () {
                                Form_ExecuteAction_FinishPost(publish);
                              },
                              null);
    }
    else {
      // Commit without prompting
      Form_ExecuteAction_FinishPost(publish);
    }
  });
}

function Form_ExecuteAction_FinishPost(publish) {
  // Block UI
  widget.UI.Block("Creating Log, please wait...");

  // Get Parameters
  var params = CreateFinishParameters();

  // Finish
  widget.UploadFiles("Finish", params, C.cboDocumentFileName.GetFileData(),
    function (data) {
      // Parse
      data = JSON.parse(data);

      // Unblock
      widget.UI.Unblock();

      // Refresh Parent
      widget.RefreshParent();

      // Refresh Workflow?
      if (mRecord.WorkflowId) widget.ActionNotificationSend("WorkflowRefresh", { workflowId: mRecord.WorkflowId }, null, true);

      // Warning?
      if (data.WarningMessage) {
        widget.UI.MsgBoxAlert("The Log was created but the following warning was given:\n\n" + data.WarningMessage, {},
          function () {
            // Close
            widget.Close();
          }
        );
      }
      else {
        // Close
        widget.Close();
      }
    },

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

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

// ===========
// Form Resize
// ===========
function Form_Resize() {
  // General

  // Tab
  tabWizard_Resize();
}

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

// ===========
// Wizard Move
// ===========
function tabWizard_Move(direction) {
  var Ok;

  // Validate
  if (direction &gt; 0) {
    tabWizard_Validate(function () { tabWizard_MovePost(direction); });
  }
  else {
    // Can always move backwards
    tabWizard_MovePost(direction);
  }
}

function tabWizard_MovePost(direction) {
  var Ok = true;

  // Find Next Tab to Move To
  if (Ok) {
    var found = false;
    var newTab = tabWizard.SelectedTabIndex();

    do {
      newTab += direction;

      switch (tabWizard.GetTabIdByIndex(newTab)) {
        default:
          found = true;
          break;
      }

      // Found?
      if (found) {
        break;
      }
      else if (newTab == tabWizard.TabCount() - 1) {
        // Just in case!
        widget.UI.MsgBoxAlert("tabWizard_MovePost: Tab not handled!");
        break;
      }
    }
    while (true);

    // Refresh the New Tab
    tabWizard_Refresh(newTab);
  }
}

function tabWizard_Refresh(newTab) {
  // Moving forward onto tab, so Load information
  if (newTab &gt;= tabWizard.SelectedTabIndex()) {
    switch (tabWizard.GetTabIdByIndex(newTab)) {
      default:
        break;
    }
  }

  // Make Tab it
  tabWizard.SelectedTabIndex(newTab);

  // Special
  switch(tabWizard.SelectedTabId()) {
    default:
      break;
  }

  // Tweak fields

  // Update Heading
  switch (tabWizard.SelectedTabId()) {
    default:
      frmMain.RefreshHeading(tabWizard.TabCaption(tabWizard.SelectedTabId()), tabWizard.TabTooltipText(tabWizard.SelectedTabId()));
      break;
  }

  // Back, Next command buttons valid?
  tabWizard_UpdateButtons();

  // Resize Wizard
  tabWizard_Resize();

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

function tabWizard_Resize() {
  switch (tabWizard.SelectedTabId()) {
    case "General":
      //C.cboContactedAt.WidthResizeFromParent();
      C.txtNotes.WidthResizeFromParent();
      C.cboFeeElement.WidthResizeFromParent();
      C.txtFeeReference.WidthResizeFromParent();
      C.txtFeeNotes.WidthResizeFromParent();
      break;

    default:
      break;
  }
}

function tabWizard_UpdateButtons() {
  // Back, Next Buttons?
  if (tabWizard.TabCount() == 1) {
    cmdBack.hide();
    cmdNext.hide();
  }
  else {
    var tabIndex = tabWizard.SelectedTabIndex();

    // Back and Next Buttons?
    cmdBack.prop("disabled", tabIndex &lt; 1);
    cmdNext.prop("disabled", tabIndex &gt;= tabWizard.TabCount() - 1);
  }

  // Finish Button
  if (tabWizard.TabCount() != 1) {
    cmdFinish.prop("disabled", !cmdNext.prop("disabled"));
  }

  if (mRecord) {
    // Only show Advanced button on relevant pages
    cmdAdvanced.hide()
    switch (tabWizard.SelectedTabId()) {
      case "General":
        if (mRecord.PageGeneralHasAdvanced) cmdAdvanced.show();
        break;
    }
  }
  else {
    cmdAdvanced.hide();
  }
}

function tabWizard_Validate(validCallback) {
  // Validate
  var Ok = tabWizard.Validate(true);

  // Other client-side validation
  if (Ok) {
    switch (tabWizard.SelectedTabId()) {
      default:
        // No validation
        validCallback();
        return;
    }
  }

  // Server-side validation
  if (Ok) {
    var params;

    switch (tabWizard.SelectedTabId()) {
      default:
        break;
    }

    if (params) {
      // Disable Form
      frmMain.FormDisable("Validating");

      // Extend parameters
      params.pageId = tabWizard.SelectedTabId();

      // Call WizardValidate method in Script
      widget.GetString("WizardValidate",
                       params,
                       function (data) { tabWizard_ValidatePost(validCallback, data); },
                       tabWizard_ValidateFail);
    }
    else {
      // No server-side validation
      validCallback();
    }
  }
}

function tabWizard_ValidatePost(validCallback, data) {
  // Enable form
  frmMain.FormEnable();

  // Parse Data
  var o = {};
  if (data) o = JSON.parse(data);

  if (o.FailedMessage) {
    // -----------------
    // Validation failed
    // -----------------
    var o = JSON.parse(data);
    widget.UI.MsgBoxAlert(o.FailedMessage, {}, function () {
      if (o.FailedControlId) $("#" + o.FailedControlId).focus();
    });
  }
  else {
    // ---------------------
    // Validation successful
    // ---------------------
    // Validation could pass back additional information, e.g., to use in tabWizard_Refresh
    switch (tabWizard.SelectedTabId()) {
      case "General":
        break;
    }

    // Callback
    validCallback();
  }
}

function tabWizard_ValidateFail(errorMessage)
{
  widget.UI.MsgBoxAlert(errorMessage);

  // Enable form
  frmMain.FormEnable();
}

// =================
// Call Phone Number
// =================
function CallPhone() {
  if (C.cboContactedAt.Text()) window.location = "tel://" + C.cboContactedAt.Text();
}

// =================
// Advanced handling
// =================
function AdvancedInitialise() {
  // Tweaks

  // General
  AdvancedInitialiseSection("Severity", mRecord.ShowSeverity);
  AdvancedInitialiseSection("Outcome", mRecord.ShowOutcome);
  AdvancedInitialiseSection("Delegate", mRecord.ShowDelegated);
  AdvancedInitialiseSection("DocumentUpload", mRecord.ShowDocumentUpload);  
}

function AdvancedInitialiseSection(id, option) {
  // Get elements
  var els=$("*[advancedId='" + id + "']");

  // Update
  switch(option.toUpperCase()) {
    case "TRUE":
      // Always show, i.e., not advanced
      break;

    case "FALSE":
      // Never show
      els.hide();
      break;

    case "ADVANCED":
      // Only show in 'Advanced' mode
      els.addClass("advanced");
      break;
  }
}

function AdvancedToggle() {
  // Toggle Advanced
  mAdvancedVisible = !mAdvancedVisible;

  // Update Controls
  if (mAdvancedVisible) {
    // Showing
    $("body").addClass("advanced-visible");
    cmdAdvanced.attr("showing", true);
  }
  else {
    // Not showing
    $("body").removeClass("advanced-visible");
    cmdAdvanced.attr("showing", false);
  }

  // Other
  switch (tabWizard.SelectedTabId()) {
    case "General":
      AdvancedToggle_General();
      break;
  }

  // Finalise
  AdvancedInitialise();

  // Force resize
  tabWizard_Resize()
}

function AdvancedToggle_General() {
  // Severity
  if (C.cboLogSeverity.VisibleRow()) {
    C.lblAction.Text("Specify Action details and Log Severity");
  }
  else {
    C.lblAction.Text("Specify Action details");
  }
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>60</TimeoutSeconds>
    <UniqueId>iLlx12UEX0aLoDzJoXhuWQ</UniqueId>
    <AllowRefresh>false</AllowRefresh>
    <Caption>Outgoing Communication</Caption>
    <HtmlWidgetAllowInitialEventCaching>false</HtmlWidgetAllowInitialEventCaching>
    <HtmlWidgetMaxHeight>1200</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>1024</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceChartsApex>false</HtmlWidgetResourceChartsApex>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <HtmlWidgetSpecialEventShowAsSummaryPage>false</HtmlWidgetSpecialEventShowAsSummaryPage>
    <HtmlWidgetSummaryPageObjectType>None</HtmlWidgetSummaryPageObjectType>
    <Icon>Communication_Outgoing</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="ShowSeverity" 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>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>false</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowOutcome" 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>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>false</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowDelegated" 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>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>false</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ShowDocumentUpload" 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>Advanced</Value>
            <Visible>true</Visible>
            <List>True,False,Advanced</List>
            <LimitToList>false</LimitToList>
            <MaxLength>8</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>TESTING</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText>These are the Parameters required by this HTML Widget to function correctly.
They are listed here for testing purposes only.</TooltipText>
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="Type" 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>Account,AccountApp,Client</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="Id" type="Text">
            <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>
            <MaxLength>20</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ReplyLogPk" type="Number">
            <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>
            <DecimalPlaces>0</DecimalPlaces>
            <GroupDigits>true</GroupDigits>
            <MaxValue />
            <MinValue />
            <NumberSpecialType>None</NumberSpecialType>
            <SpinChange>1</SpinChange>
          </Parameter>
          <Parameter name="WorkflowPk" type="Number">
            <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>
            <DecimalPlaces>0</DecimalPlaces>
            <GroupDigits>true</GroupDigits>
            <MaxValue />
            <MinValue />
            <NumberSpecialType>None</NumberSpecialType>
            <SpinChange>1</SpinChange>
          </Parameter>
          <Parameter name="WorkflowItemPk" type="Number">
            <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>
            <DecimalPlaces>0</DecimalPlaces>
            <GroupDigits>true</GroupDigits>
            <MaxValue />
            <MinValue />
            <NumberSpecialType>None</NumberSpecialType>
            <SpinChange>1</SpinChange>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Include Contact Types (Account and Account App)</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="IncludeBroker" type="Boolean">
            <BlankTip />
            <Caption>Include Broker</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="IncludeDealer" type="Boolean">
            <BlankTip />
            <Caption>Include Dealer</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="IncludeEmployees" type="Boolean">
            <BlankTip />
            <Caption>Include Employees</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="IncludeGuarantors" type="Boolean">
            <BlankTip />
            <Caption>Include Guarantors</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="IncludeInsurer" type="Boolean">
            <BlankTip />
            <Caption>Include Insurer (Account only)</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="IncludeManagerAccount" type="Boolean">
            <BlankTip />
            <Caption>Include Manager</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="IncludeOtherContactMethods" type="Boolean">
            <BlankTip />
            <Caption>Include Other Contact Methods (Account only)</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="IncludeOtherRoles" type="Boolean">
            <BlankTip />
            <Caption>Include Other Roles</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>Include Contact Types (Client)</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="IncludeEmail" type="Boolean">
            <BlankTip />
            <Caption>Include Email</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="IncludeEmployments" type="Boolean">
            <BlankTip />
            <Caption>Include Employments</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="IncludeFax" type="Boolean">
            <BlankTip />
            <Caption>Include Fax</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="IncludeManagerClient" type="Boolean">
            <BlankTip />
            <Caption>Include Manager</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="IncludeName" type="Boolean">
            <BlankTip />
            <Caption>Include Name</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="IncludeOther" type="Boolean">
            <BlankTip />
            <Caption>Include Other</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="IncludePhone" type="Boolean">
            <BlankTip />
            <Caption>Include Phone</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="IncludeSms" type="Boolean">
            <BlankTip />
            <Caption>Include SMS</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>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>