<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2022-06-16T23:01:19.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2022-06-16T22:39:46.7800000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2022-06-16T22:45:03.2090000</UpdatedUtcDate>
    <ScriptId>PPSRB2GSEARCH</ScriptId>
    <Description>PPSR B2G Search</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Category />
    <Code>' HtmlWidget_PPSRB2GAUSearch
Option Explicit On
Option Strict On

' #################################################################
' PPSR B2G AU Search wizard
'
' Version: 1.04 (17/06/2022)
'
' Usage: System-defined HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.01  02/08/2021  ISS                Updated
'    1.02  04/11/2021  ISS      J027712   Removed reference to obsoleted Function
'          11/11/2021  ISS      J027715   Summary page issue in desktop
'    1.03  13/12/2021  ISS      J028027   Can now be launched from Service Log HTML Widget
'          23/12/2021  ISS      J028080   Updated Tooltips
'          01/02/2022  ISS      J028062   Allowed more Search Types when linked to a Workflow
'          21/03/2022  ISS      J028229   Restricted Search Types when performing for an Account Application
'    1.04  17/06/2022  ISS      J028983   Updated obsoleted functions
' #################################################################

' Constants
Private Const FORM_KEY As String = "PPSRB2GAUSearch"

' Common Parameters
Private mAccountAppApplicantPk As Integer
Private mAccountAppCollateralPk As Integer
Private mAccountAppId As String
Private mClientId As String
Private mSecurityStmtId As String
Private mSecurityStmtItemPk As Integer
Private mServiceLogPk As Integer
Private mShowRequestResponseXml As Boolean
Private mWorkflowItemPk As Integer
Private mWorkflowPk As Integer

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

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

  Dim AccountAppApplicantPk As Integer
  Dim AccountAppId As String
  Dim ClientId As String

  ' 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 Common Parameters
  With mCombinedParameters
    mAccountAppId = .GetString("AccountAppId")
    mAccountAppApplicantPk = .GetInteger("AccountAppApplicantPk")
    mAccountAppCollateralPk = .GetInteger("AccountAppCollateralPk")
    mClientId = .GetString("ClientId")
    mShowRequestResponseXml = .GetBoolean("ShowRequestResponseXml")
    mSecurityStmtId = .GetString("SecurityStmtId")
    mSecurityStmtItemPk = .GetInteger("SecurityStmtItemPk")
    mServiceLogPk = .GetInteger("ServiceLogPk")
    mWorkflowPk = .GetInteger("WorkflowPk")
    mWorkflowItemPk = .GetInteger("WorkflowItemPk")
  End With

  ' Update Parameters from Workflow
  If mServiceLogPk = 0 AndAlso mWorkflowPk &lt;&gt; 0 AndAlso mWorkflowItemPk &lt;&gt; 0 Then
    If finBL.HtmlWidgetUtilities.GetSourceObjectDetailsFromWorkflowItem(mWorkflowPk, mWorkflowItemPk, ClientId, "", AccountAppId, AccountAppApplicantPk) Then
      If mAccountAppApplicantPk = 0 Then mAccountAppApplicantPk = AccountAppApplicantPk
      If Len(mAccountAppId) = 0 Then mAccountAppId = AccountAppId
      If Len(mClientId) = 0 Then mClientId = ClientId
    End If
  End If

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

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

    Case "GetPreviousSearches"
      ' Get Previous PPSR G2B Searches
      Main = GetPreviousSearches(returnValue)

    Case "GetSearchResultDetailed"
      ' Get Search Result Detailed
      Main = GetSearchResultDetailed(returnValue)

    Case "GetSearchResultPreview"
      ' Get Search Result Preview
      Main = GetSearchResultPreview(returnValue)

    Case "GetXml"
      ' Get Request / Response XML
      Main = GetXml(returnValue)

    Case "PerformSearch"
      ' Perform PPSR B2G Search
      Main = PerformSearch(parametersJson, 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;
'''  Get Account Application.
''' &lt;/summary&gt;
Private Function GetAccountApp(ByRef accountApp As finAccountApp,
                               collateralItemDescription As String) As Boolean

  Dim AccountAppCollateralItem As finAccountAppCollateralItem
  Dim Client As finClient
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef Parameters
  accountApp = Nothing

  ' Initialise
  accountApp = finBL.CreateAccountApp()

  ' Load and Validate
  If accountApp.Load(mAccountAppId) Then
    If accountApp.IsNew Then
      Success = False
      finBL.Error.ErrorBegin("Invalid AccountAppId.")
    ElseIf mAccountAppApplicantPk &lt;&gt; 0 AndAlso Not accountApp.Applicants.ExistsPk(mAccountAppApplicantPk) Then
      Success = False
      finBL.Error.ErrorBegin("Invalid AccountAppApplicantPk.")
    ElseIf mAccountAppCollateralPk &lt;&gt; 0 AndAlso Not accountApp.CollateralItems.ExistsPk(mAccountAppCollateralPk) Then
      Success = False
      finBL.Error.ErrorBegin("Invalid AccountAppCollateralPk.")
    End If

    ' Get Account Applicant Applicant
    If Success AndAlso mAccountAppApplicantPk &lt;&gt; 0 Then
      If accountApp.Applicants.ItemByPk(mAccountAppApplicantPk).CreateClient(False, Client) Then
        mClientId = Client.ClientId
      Else
        Success = False
      End If
    End If

    ' Find Collateral Item from Description
    If Success AndAlso Len(collateralItemDescription) &lt;&gt; 0 Then
      For Each AccountAppCollateralItem In accountApp.CollateralItems
        If Len(AccountAppCollateralItem.Description) &lt;&gt; 0 Then
          If StrComp(AccountAppCollateralItem.Description, collateralItemDescription, CompareMethod.Text) = 0 Then
            mAccountAppCollateralPk = AccountAppCollateralItem.Pk
            Exit For
          End If
        End If
      Next
    End If

    ' Ensure Collateral is Aircraft or Motor Vehicle
    If Success AndAlso mAccountAppCollateralPk &lt;&gt; 0 Then
      Select Case accountApp.CollateralItems.ItemByPk(mAccountAppCollateralPk).SecurityBaseType
        Case isefinSecurityBaseType.Aircraft, isefinSecurityBaseType.Boat, isefinSecurityBaseType.MotorVehicle
          ' Ok

        Case Else
          ' Only valid if Intellectual Property (Serial Numbered Good)
          If Not finBL.SecurityStmtFunctions.IsValidIntellectualPropertyForPPSRB2GAU(accountApp.CollateralItems.ItemByPk(mAccountAppCollateralPk)) Then
            Success = False
            finBL.Error.ErrorBegin("Invalid Account Application Collateral Base Type.")
          End If
      End Select
    End If
  Else
    Success = False
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Client Akas for PPSR use.
''' &lt;/summary&gt;
Private Function GetClientAkas(client As finClient) As List(Of ClientAka)

  Dim ClientAka As finClientAka
  Dim ClientAkas As List(Of ClientAka)

  ' Initialise
  ClientAkas = New List(Of ClientAka)

  ' Add Akas
  If client.IsIndividualOrSoleTrader Then
    ' Client Name
    ClientAkas.Add(New ClientAka(client.FirstName, client.LastName, client.MiddleNames, "", client.Title, client.DateOfBirth))

    ' AKAs
    For Each ClientAka In client.Akas
      With ClientAka
        ClientAkas.Add(New ClientAka(.FirstName, .LastName, .MiddleNames, .Notes, .Title, .DateOfBirth))
      End With
    Next
  Else
    ' Legal and Company Names
    If Len(client.LegalName) &lt;&gt; 0 Then
      ClientAkas.Add(New ClientAka(client.LegalName, "", client.BusinessNumber, client.OrganisationNumber, client.ClientClass))
    End If
    ClientAkas.Add(New ClientAka(client.Name, "", client.BusinessNumber, client.OrganisationNumber, client.ClientClass))

    ' AKAs
    For Each ClientAka In client.Akas
      With ClientAka
        ClientAkas.Add(New ClientAka(.Name, .Notes, client.BusinessNumber, client.OrganisationNumber, client.ClientClass))
      End With
    Next
  End If

  Return ClientAkas

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 AccountApp As finAccountApp
  Dim AccountAppCollateralItem As finAccountAppCollateralItem
  Dim Client As finClient
  Dim ClientClass As finClientClass
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim IsAccountAppApplicant As Boolean
  Dim List As ISList
  Dim Request As ISG2BSearchFsRequest
  Dim SearchResultsJson As String
  Dim SearchTypeList As ISCodeDescriptionList
  Dim SecurityStmt As finSecurityStmt
  Dim SecurityStmtItemBase As finSecurityStmtItemBase
  Dim ServiceLog As ISServiceLog
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise
  List = New ISList()
  Request = finBL.SecurityRegister.CreateG2BSearchFsRequest()
  SearchTypeList = finBL.Runtime.CreateCodeDescriptionList()

  ' Validate
  If Request Is Nothing Then
    Success = False
    finBL.Error.ErrorBegin("This service is not available.")
  ElseIf Len(mAccountAppId) = 0 AndAlso (mAccountAppApplicantPk &lt;&gt; 0 OrElse mAccountAppCollateralPk &lt;&gt; 0) Then
    Success = False
    finBL.Error.ErrorBegin("An AccountAppId must be specified if an Applicant or AccountAppCollateralPk has been supplied.")
  ElseIf Len(mSecurityStmtId) = 0 AndAlso mSecurityStmtItemPk &lt;&gt; 0 Then
    Success = False
    finBL.Error.ErrorBegin("A SecurityStmtId must be specified if a SecurityStmtItemPk has been supplied.")
  ElseIf mAccountAppApplicantPk &lt;&gt; 0 AndAlso mAccountAppCollateralPk &lt;&gt; 0 Then
    Success = False
    finBL.Error.ErrorBegin("An Applicant or Collateral can only be specified.")
  ElseIf mWorkflowPk &lt;&gt; 0 AndAlso Len(mSecurityStmtId) &lt;&gt; 0 Then
    Success = False
    finBL.Error.ErrorBegin("Security Statements do not support Workflow integration.")
  ElseIf mWorkflowPk = 0 AndAlso mWorkflowItemPk &lt;&gt; 0 Then
    Success = False
    finBL.Error.ErrorBegin("You must also specify the WorkflowPk if a Workflow Item has been specified.")
  ElseIf mWorkflowPk &lt;&gt; 0 AndAlso mWorkflowItemPk = 0 Then
    Success = False
    finBL.Error.ErrorBegin("You must also specify the WorkflowItemPk of the Workflow Item to Action if a Workflow has been specified.")
  End If

  ' Validate Id entry
  If Success AndAlso mServiceLogPk = 0 Then
    List.Clear()
    If Len(mAccountAppId) &lt;&gt; 0 Then List.Add(mAccountAppId)
    If Len(mClientId) &lt;&gt; 0 Then List.Add(mClientId)
    If Len(mSecurityStmtId) &lt;&gt; 0 Then List.Add(mSecurityStmtId)

    If List.Count &gt; 1 Then
      Success = False
      finBL.Error.ErrorBegin("Only one of 'Account Application', 'Client' or 'Security Statement' can be specified.")
    End If
  End If

  ' Get Account Application
  If Success AndAlso Len(mAccountAppId) &lt;&gt; 0 AndAlso mServiceLogPk = 0 Then
    Success = GetAccountApp(AccountApp, "")
  End If

  ' Get Client
  If Success AndAlso Len(mClientId) &lt;&gt; 0 AndAlso mServiceLogPk = 0 Then
    Client = finBL.CreateClient()
    Success = Client.Load(mClientId)
  End If

  ' Get Security Statement
  If Success AndAlso Len(mSecurityStmtId) &lt;&gt; 0 AndAlso mServiceLogPk = 0 Then
    Success = GetSecurityStmt(SecurityStmt, "")
  End If

  ' Get Existing Search Results
  If Success AndAlso mServiceLogPk &lt;&gt; 0 Then
    Success = GetSearchResults(mServiceLogPk, SearchResultsJson)
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Record
      ' -------------------
      ' Account Application
      ' -------------------
      If AccountApp IsNot Nothing Then
        .AccountAppId = AccountApp.AccountAppId
        .AccountAppName = AccountApp.Name

        If mAccountAppApplicantPk = 0 Then
          ' No Applicant specified - assume Collateral
          If mAccountAppCollateralPk = 0 Then
            ' No Collateral Item specified, preload all Aircraft &amp; Motor Vehicles
            For Each AccountAppCollateralItem In AccountApp.CollateralItems
              Select Case AccountAppCollateralItem.SecurityBaseType
                Case isefinSecurityBaseType.Aircraft, isefinSecurityBaseType.MotorVehicle, isefinSecurityBaseType.Boat
                  If Len(AccountAppCollateralItem.Description) &lt;&gt; 0 Then
                    .SecurityItems.Add(New SecurityItem(AccountAppCollateralItem))
                  End If

                Case isefinSecurityBaseType.SerialNumberedGood
                  If finBL.SecurityStmtFunctions.IsValidIntellectualPropertyForPPSRB2GAU(AccountAppCollateralItem.SecurityTypePk) Then
                    .SecurityItems.Add(New SecurityItem(AccountAppCollateralItem))
                  End If
              End Select
            Next
          Else
            ' Security Item specified, only load the single item
            If AccountApp.CollateralItems.ExistsPk(mAccountAppCollateralPk) Then
              .AccountAppCollateralItemPk = mAccountAppCollateralPk
              .SecurityItems.Add(New SecurityItem(AccountApp.CollateralItems.ItemByPk(mAccountAppCollateralPk)))

              ' Restrict Search Types to match single Security Item
              SearchTypeList.Add(finBL.Enums.iseSecurityRegisterSearchType_FromString(.SecurityItems(0).SearchType).ToString(), .SecurityItems(0).SearchType)
            Else
              Success = False
              finBL.Error.ErrorBegin("Invalid Collateral Item.")
            End If
          End If

          ' Valid Search Types
          If SearchTypeList.Count = 0 Then
            SearchTypeList.Add(iseSecurityRegisterSearchType.PreviousSearch.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.PreviousSearch))
            SearchTypeList.Add(iseSecurityRegisterSearchType.Aircraft.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Aircraft))
            SearchTypeList.Add(iseSecurityRegisterSearchType.IntellectualProperty.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.IntellectualProperty))
            SearchTypeList.Add(iseSecurityRegisterSearchType.MotorVehicle.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.MotorVehicle))
            SearchTypeList.Add(iseSecurityRegisterSearchType.Watercraft.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Watercraft))
          End If
        Else
          IsAccountAppApplicant = True
          .AccountAppApplicantPk = mAccountAppApplicantPk

          ' Applicant Specified
          If AccountApp.Applicants.ItemByPk(mAccountAppApplicantPk).CreateClient(False, Client) Then
            ' Set Defaults
            If Len(Client.ClientId) = 0 Then
              Client.ClientId = "[NEW]"
            End If
          Else
            Success = False
          End If
        End If
      End If

      ' ------
      ' Client
      ' ------
      If Client IsNot Nothing Then
        .ClientAkas = GetClientAkas(Client)
        .ClientId = Client.ClientId
        .ClientName = Client.Name

        ' Allow Previous Search
        If Not IsAccountAppApplicant Then
          SearchTypeList.Add(iseSecurityRegisterSearchType.PreviousSearch.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.PreviousSearch))
        End If

        ' Individual / Organisation
        If Client.IsOrganisation Then
          SearchTypeList.Add(iseSecurityRegisterSearchType.DebtorOrganisation.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.DebtorOrganisation))
          If Not IsAccountAppApplicant Then SearchTypeList.Add(iseSecurityRegisterSearchType.DebtorOrganisationDateRange.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.DebtorOrganisationDateRange))
        Else
          SearchTypeList.Add(iseSecurityRegisterSearchType.DebtorPerson.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.DebtorPerson))
          If Not IsAccountAppApplicant Then SearchTypeList.Add(iseSecurityRegisterSearchType.DebtorPersonDateRange.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.DebtorPersonDateRange))
        End If
      End If

      ' ------------------
      ' Security Statement
      ' ------------------
      If SecurityStmt IsNot Nothing Then
        .SecurityStmtId = SecurityStmt.SecurityStmtId
        .SecurityStmtDescription = SecurityStmt.Description

        If mSecurityStmtItemPk = 0 Then
          ' No Security Item specified, preload all Aircraft &amp; Motor Vehicles
          For Each SecurityStmtItemBase In SecurityStmt.SecurityItems
            Select Case SecurityStmtItemBase.BaseType
              Case isefinSecurityBaseType.Aircraft, isefinSecurityBaseType.MotorVehicle, isefinSecurityBaseType.Boat
                .SecurityItems.Add(New SecurityItem(SecurityStmtItemBase))

              Case isefinSecurityBaseType.SerialNumberedGood
                If finBL.SecurityStmtFunctions.IsValidIntellectualPropertyForPPSRB2GAU(SecurityStmtItemBase.SecurityTypePk) Then
                  .SecurityItems.Add(New SecurityItem(SecurityStmtItemBase))
                End If
            End Select
          Next
        Else
          ' Security Item specified, only load the single item
          .SecurityStmtItemPk = mSecurityStmtItemPk
          .SecurityItems.Add(New SecurityItem(SecurityStmt.SecurityItems.ItemByPk(mSecurityStmtItemPk)))

          ' Restrict Search Types to match single Security Item
          SearchTypeList.Add(iseSecurityRegisterSearchType.PreviousSearch.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.PreviousSearch))
          SearchTypeList.Add(finBL.Enums.iseSecurityRegisterSearchType_FromString(.SecurityItems(0).SearchType).ToString(), .SecurityItems(0).SearchType)
        End If

        ' Valid Search Types
        If SearchTypeList.Count = 0 Then
          SearchTypeList.Add(iseSecurityRegisterSearchType.PreviousSearch.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.PreviousSearch))
          SearchTypeList.Add(iseSecurityRegisterSearchType.Aircraft.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Aircraft))
          SearchTypeList.Add(iseSecurityRegisterSearchType.IntellectualProperty.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.IntellectualProperty))
          SearchTypeList.Add(iseSecurityRegisterSearchType.MotorVehicle.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.MotorVehicle))
          SearchTypeList.Add(iseSecurityRegisterSearchType.Watercraft.ToString(), finBL.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Watercraft))
        End If
      End If

      ' Service Log
      .RunFromServiceLog = (mServiceLogPk &lt;&gt; 0)
      If .RunFromServiceLog Then
        .SearchResultsJson = SearchResultsJson
        .ServiceLogCaption = String.Format("Service Log #{0}.", mServiceLogPk)
      End If

      ' Workflow
      If mWorkflowPk &lt;&gt; 0 AndAlso mServiceLogPk = 0 Then
        .WorkflowDescription = finBL.WorkflowFunctions.GetRecordCodeDescription(mWorkflowPk, .WorkflowId)
      End If

      ' Allow all Search Types if linked to a Workflow (repopulated below under 'Lists')
      If mWorkflowPk &lt;&gt; 0 Then
        SearchTypeList.Clear()
      End If

      ' Lists
      .GrantorCollateralTypeDefault = finBL.Enums.iseSecurityRegisterSearchCollateralType_ToString(iseSecurityRegisterSearchCollateralType.All)
      .GrantorCollateralTypes = finBL.Enums.iseSecurityRegisterSearchCollateralType_GetList().ToCsvString()
      If SearchTypeList.Count = 0 Then SearchTypeList = finBL.Enums.iseSecurityRegisterSearchType_ToCodeDescriptionList()
      .SearchTypes = SearchTypeList.ToJsonObject()

      ' Organisation Types
      List.Clear()
      For Each ClientClass In finBL.ClientClasses
        With ClientClass
          If Len(.BusinessNumberAbbrev) &lt;&gt; 0 Then List.Add(.BusinessNumberAbbrev, True)
          If Len(.CompanyNumberAbbrev) &lt;&gt; 0 Then List.Add(.CompanyNumberAbbrev, True)
        End With
      Next
      List.Add("Organisation Name")
      .OrganisationTypes = List.ToCsvString()

      ' Search Types
      .SerialNumberSearchTypes.Add(New SerialNumberSearchType(iseSecurityRegisterSearchType.Aircraft))
      .SerialNumberSearchTypes.Add(New SerialNumberSearchType(iseSecurityRegisterSearchType.IntellectualProperty))
      .SerialNumberSearchTypes.Add(New SerialNumberSearchType(iseSecurityRegisterSearchType.MotorVehicle))
      .SerialNumberSearchTypes.Add(New SerialNumberSearchType(iseSecurityRegisterSearchType.Watercraft))

      ' Configuration
      .CanViewServiceLog = finBL.CurrentUser.Permissions.Allow("ServiceLogs.View")
      .ShowRequestResponseXml = mShowRequestResponseXml
      .IsAdministrator = finBL.CurrentUser.IsAdministrator

      ' Test Mode
      If mServiceLogPk = 0 Then
        .TestMode = finBL.SettingsUser.CostCentreTestModeResolved
      ElseIf finBL.Database.GetServiceLog(mServiceLogPk, ServiceLog) Then
        .TestMode = ServiceLog.TestMode
      Else
        Success = False
      End If

      ' Other
      .SearchFromDefaultDate = finBL.HtmlWidgetUtilities.GetJsonUtcDateFromDatabaseDate(finBL.TimeZoneFunctions.GetCurrentDatabaseDate())

      ' Form Heading
      .FormHeading = ScriptInfo.ScriptCaption
      If Len(.FormHeading) = 0 Then .FormHeading = "PPSR B2G Search"
      If .TestMode Then .FormHeading = .FormHeading &amp; " (Test Mode)"
    End With
  End If

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

  Return Success

End Function

''' &lt;summary&gt;
'''  Get previous PPSR B2G Searches.
''' &lt;/summary&gt;
Private Function GetPreviousSearches(ByRef returnValue As String) As Boolean

  Dim DateFrom As Date
  Dim DateTo As Date
  Dim IncludeAllUsers As Boolean
  Dim IncludeErrors As Boolean
  Dim PreviousSearchResults As List(Of PreviousSearchResult)
  Dim SecurityItemDescription As String
  Dim SecurityRegisterPreviousSearch As finSecurityRegisterPreviousSearch
  Dim SecurityRegisterPreviousSearches As finSecurityRegisterPreviousSearches
  Dim Success As Boolean
  Dim UserPk As Integer

  ' Assume Success
  Success = True

  ' Get Parameters
  With mCombinedParameters
    DateFrom = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(.GetDate("DateFrom"))
    DateTo = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(.GetDate("DateTo"))
    IncludeAllUsers = .GetBoolean("IncludeAllUsers")
    IncludeErrors = .GetBoolean("IncludeErrors")
    SecurityItemDescription = .GetString("SecurityItemDescription")
  End With

  ' User Pk
  If finBL.CurrentUser.IsAdministrator AndAlso IncludeAllUsers Then
    UserPk = 0
  Else
    UserPk = finBL.CurrentUser.UserPk
  End If

  ' Initialise
  PreviousSearchResults = New List(Of PreviousSearchResult)
  SecurityRegisterPreviousSearches = finBL.SecurityRegister.CreateSecurityRegisterPreviousSearches()

  ' Get Searches
  With SecurityRegisterPreviousSearches
    ' Update Items if required
    If Len(mAccountAppId) &lt;&gt; 0 AndAlso Len(SecurityItemDescription) &lt;&gt; 0 Then
      Success = GetAccountApp(Nothing, SecurityItemDescription)
    ElseIf Len(SecurityItemDescription) &lt;&gt; 0 Then
      Success = GetSecurityStmt(Nothing, SecurityItemDescription)
    End If

    ' Load Previous Searches
    If Len(mAccountAppId) &lt;&gt; 0 Then
      ' Account Application
      Success = .LoadAccountApp(mAccountAppId, DateFrom, DateTo, mAccountAppApplicantPk, mAccountAppCollateralPk, UserPk, IncludeErrors)
    ElseIf Len(mClientId) &lt;&gt; 0 Then
      ' Client
      Success = .LoadClient(mClientId, DateFrom, DateTo, UserPk, IncludeErrors)
    ElseIf Len(mSecurityStmtId) &lt;&gt; 0 Then
      ' Security Statement
      Success = .LoadSecurityStmt(mSecurityStmtId, DateFrom, DateTo, mSecurityStmtItemPk, UserPk, IncludeErrors)
    Else
      ' Load all
      Success = .Load(DateFrom, DateTo, UserPk, IncludeErrors)
    End If
  End With

  ' Add
  If Success Then
    For Each SecurityRegisterPreviousSearch In SecurityRegisterPreviousSearches
      PreviousSearchResults.Add(New PreviousSearchResult(SecurityRegisterPreviousSearch))
    Next
  End If

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

  Return Success

End Function

''' &lt;summary&gt;
'''  Get the detailed Search Result (Financing Statement)
''' &lt;/summary&gt;
Private Function GetSearchResultDetailed(ByRef returnValue As String) As Boolean

  Dim Index As Integer
  Dim Success As Boolean
  Dim ServiceLogPk As Integer
  Dim SearchFsResponse As ISG2BSearchFsResponse

  ' Assume Success
  Success = True

  ' Get Parameters
  With mCombinedParameters
    Index = .GetInteger("Index")
    ServiceLogPk = .GetInteger("ServiceLogPk")
  End With

  ' Get Response
  Success = finBL.SecurityRegister.LoadSearchFsResponseFromServiceLog(ServiceLogPk, SearchFsResponse)

  ' Validate
  If Success Then
    If Index &lt; 0 OrElse Index &gt;= SearchFsResponse.Count Then
      Success = False
      finBL.Error.ErrorBegin("Invalid Search Result Index.")
    End If
  End If

  ' Get Summary
  If Success Then
    With SearchFsResponse(Index)
      If .RestrictionReason = iseSecurityRegisterRestrictionReason.None AndAlso Len(.FinancingStatement.FinancingStatementId) = 0 Then
        Success = False
        finBL.Error.ErrorBegin("Registration has not be loaded.")
      Else
        returnValue = finBL.SummaryPageFunctions.SecurityStmtFinancingStatementPPSRB2GAU(False, .FinancingStatement, .RestrictionReason, finBL.HtmlWidgetUtilities.CreateScriptContextData(ScriptInfo, FORM_KEY))
      End If
    End With
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get PPSR details about a Search Result.
''' &lt;/summary&gt;
Private Function GetSearchResultPreview(ByRef returnValue As String) As Boolean

  Dim Index As Integer
  Dim kvl As ISKeyValueList
  Dim SearchCriteria As String
  Dim SearchDate As Date
  Dim SearchFsResponse As ISG2BSearchFsResponse
  Dim SearchType As String
  Dim ServiceLogPk As Integer
  Dim Success As Boolean
  Dim UserPk As Integer

  ' Assume Success
  Success = True

  ' Get Parameters
  With mCombinedParameters
    Index = .GetInteger("Index")
    SearchCriteria = .GetString("SearchCriteria")
    SearchDate = finBL.HtmlWidgetUtilities.GetDatabaseDateTimeFromJsonUtcDateTime(.GetDate("Date"))
    SearchType = .GetString("SearchType")
    ServiceLogPk = .GetInteger("ServiceLogPk")
    UserPk = .GetInteger("UserPk")
  End With

  ' Get Response
  Success = finBL.SecurityRegister.LoadSearchFsResponseFromServiceLog(ServiceLogPk, SearchFsResponse)

  ' Get Search information from previous searches
  If Success AndAlso Len(SearchCriteria) = 0 AndAlso Len(SearchType) = 0 Then
    Success = GetSearchResultPreviewInfo(ServiceLogPk, SearchCriteria, SearchType)
  End If

  If Success Then
    ' Properties
    kvl = finBL.CreateKeyValueList()
    With kvl
      .SetString("SearchCriteria", SearchCriteria)
      .SetString("SearchType", SearchType)
      .SetDate("Date", SearchDate)
      .SetInteger("UserPk", UserPk)
    End With

    ' Generate Summary HTML
    returnValue = finBL.SummaryPageFunctions.SecurityStmtFinancingStatementPPSRB2GAUSearchFsResponse(False, SearchFsResponse, Index, kvl, finBL.HtmlWidgetUtilities.CreateScriptContextData(ScriptInfo, FORM_KEY))
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Search Criteria &amp; Type from a previous search.
''' &lt;/summary&gt;
Private Function GetSearchResultPreviewInfo(serviceLogPk As Integer,
                                            ByRef searchCriteria As String,
                                            ByRef searchType As String) As Boolean

  Dim SecurityRegisterPreviousSearches As finSecurityRegisterPreviousSearches
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef Parameters
  searchCriteria = ""
  searchType = ""

  ' Initialise
  SecurityRegisterPreviousSearches = finBL.SecurityRegister.CreateSecurityRegisterPreviousSearches()

  ' Perform Search
  Success = SecurityRegisterPreviousSearches.LoadServiceLog(serviceLogPk)

  ' Get Results
  If Success Then
    If SecurityRegisterPreviousSearches.Count = 1 Then
      With SecurityRegisterPreviousSearches(0)
        searchCriteria = .SearchCriteria
        searchType = .SearchTypeText
      End With
    End If
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Search Results from a Service Log.
''' &lt;/summary&gt;
Private Function GetSearchResults(serviceLogPk As Integer,
                                  ByRef returnValue As String) As Boolean

  Dim Data As Object
  Dim Html As String
  Dim Response As ISG2BSearchFsResponse
  Dim ServiceLog As ISServiceLog
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Load Service Log
  Success = finBL.Database.GetServiceLog(serviceLogPk, ServiceLog)
  
  ' Validate
  If Success Then
    If StrComp(ServiceLog.GetSummaryPageCaption(), "PPSR B2G Search", CompareMethod.Text) &lt;&gt; 0 Then
      Success = False
      finBL.Error.ErrorBegin("Service Log does not contain a PPSR B2G (Australia) Search.")
    End If
  End If

  ' Get Response
  If Success Then
    Success = finBL.SecurityRegister.LoadSearchFsResponseFromServiceLog(ServiceLog.Pk, Response)
  End If

  ' Retrieve Summary if there are no results (for the Search Criteria page)
  If Success Then
    If Response.Count = 0 Then
      With mCombinedParameters
        .SetInteger("Index", -1)
        .SetInteger("ServiceLogPk", ServiceLog.Pk)
      End With

      ' Do not error if the HTML cannot be generated
      GetSearchResultPreview(Html)
    End If
  End If

  ' Data
  If Success Then
    Data = New With {
      .NoResultsHtml = Html,
      .Response = Response.ToHtmlWidgetJsonObject(),
      .ServiceLogPk = ServiceLog.Pk
    }
  End If

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

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Security Statement.
''' &lt;/summary&gt;
Private Function GetSecurityStmt(ByRef securityStmt As finSecurityStmt,
                                 securityItemDescription As String) As Boolean

  Dim SecurityStmtItemBase As finSecurityStmtItemBase
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef Parameters
  securityStmt = Nothing

  ' Load and Validate
  If Len(mSecurityStmtId) &lt;&gt; 0 Then
    securityStmt = finBL.CreateSecurityStmt()

    If securityStmt.Load(mSecurityStmtId) Then
      If securityStmt.IsNew Then
        Success = False
        finBL.Error.ErrorBegin("Invalid SecurityStmtId.")
      ElseIf mSecurityStmtItemPk &lt;&gt; 0 AndAlso Not securityStmt.SecurityItems.ExistsPk(mSecurityStmtItemPk) Then
        Success = False
        finBL.Error.ErrorBegin("Invalid SecurityStmtItemPk.")
      End If

      ' Set Item
      If Success AndAlso Len(securityItemDescription) &lt;&gt; 0 Then
        For Each SecurityStmtItemBase In securityStmt.SecurityItems
          If StrComp(SecurityStmtItemBase.Description, securityItemDescription, CompareMethod.Text) = 0 Then
            mSecurityStmtItemPk = SecurityStmtItemBase.Pk
            Exit For
          End If
        Next
      End If

      ' Ensure Security Item is Aircraft or Motor Vehicle
      If Success AndAlso mSecurityStmtItemPk &lt;&gt; 0 Then
        Select Case securityStmt.SecurityItems.ItemByPk(mSecurityStmtItemPk).BaseType
          Case isefinSecurityBaseType.Aircraft, isefinSecurityBaseType.Boat, isefinSecurityBaseType.MotorVehicle
            ' Ok

          Case Else
            ' Only valid if Intellectual Property (Serial Numbered Good)
            If Not finBL.SecurityStmtFunctions.IsValidIntellectualPropertyForPPSRB2GAU(securityStmt.SecurityItems.ItemByPk(mSecurityStmtItemPk)) Then
              Success = False
              finBL.Error.ErrorBegin("Invalid Security Statement Item Base Type.")
            End If
        End Select
      End If
    Else
      Success = False
    End If
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Wizard Finish Parameters from JSON string.
''' &lt;/summary&gt;
Private Function GetWizardFinishParameters(parametersJson As String,
                                           ByRef wizardFinishParameters As WizardFinishParameters) As Boolean

  Dim obj As Object
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Initialise ByRef Parameters
  wizardFinishParameters = Nothing

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

  Return Success

End Function

''' &lt;summary&gt;
'''  Returns Request / Response XML.
''' &lt;/summary&gt;
Private Function GetXml(ByRef returnValue As String) As Boolean

  Dim Success As Boolean
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogPk As Integer
  Dim Type As String

  ' Assume Success
  Success = True

  ' Get Parameters
  With mCombinedParameters
    ServiceLogPk = .GetInteger("ServiceLogPk")
    Type = .GetString("Type")
  End With

  ' Get Service Log
  Success = finBL.Database.GetServiceLog(ServiceLogPk, ServiceLog)

  ' Get Request / Response
  If Success Then
    Select Type
      Case "Request"
        returnValue = ServiceLog.Request
      Case "Response"
        returnValue = ServiceLog.Response
      Case Else
        Success = False
        finBL.Error.ErrorBegin("Invalid Xml Type.")
    End Select
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Perform PPSR B2G Search.
''' &lt;/summary&gt;
Private Function PerformSearch(parametersJson As String,
                               ByRef returnValue As String) As Boolean

  Dim AccountAppLog As finAccountAppLog
  Dim ClientLog As finClientLog
  Dim Errors As ISSecurityRegisterErrors
  Dim LogSubject As String
  Dim Request As ISG2BSearchFsRequest
  Dim Response As ISG2BSearchFsResponse
  Dim SecurityStmtItemLog As finSecurityStmtItemLog
  Dim SecurityStmtLog As finSecurityStmtLog
  Dim ServiceLogCreateDetails As ISServiceLogCreateDetails
  Dim ServiceLogPk As Integer
  Dim Success As Boolean
  Dim Warning As String
  Dim WizardFinishParameters As WizardFinishParameters

  ' Assume Success
  Success = True

  ' Get Wizard Finish Parameters
  Success = GetWizardFinishParameters(parametersJson, WizardFinishParameters)

  ' New Search / Existing Search
  If WizardFinishParameters.ServiceLogPk = 0 Then
    ' New Search
    ' Update Account Application Information if required
    If Success AndAlso Len(mAccountAppId) &lt;&gt; 0 Then
      Success = GetAccountApp(Nothing, WizardFinishParameters.SecurityItemDescription)
    End If

    ' Update Security Item if required
    If Success AndAlso Len(mSecurityStmtId) &lt;&gt; 0 Then
      Success = GetSecurityStmt(Nothing, WizardFinishParameters.SecurityItemDescription)
    End If

    ' Build Search
    If Success Then
      ' Initialise
      Request = finBL.SecurityRegister.CreateG2BSearchFsRequest()
      With Request
        ' Search
        .SearchType = finBL.Enums.iseSecurityRegisterSearchType_FromString(WizardFinishParameters.SearchType)
        .BillingReference = WizardFinishParameters.BillingReference
        .AcceptDeclaration = WizardFinishParameters.AcceptDeclaration

        ' Financing Statement
        .FinancingStatementId = WizardFinishParameters.FinancingStatementId
        .FinancingStatementIncludeHistory = WizardFinishParameters.FinancingStatementIncludeHistory

        ' Debtor Search
        .ClientId = mClientId
        .OrganisationType = WizardFinishParameters.OrganisationType
        .CompanyNumber = WizardFinishParameters.CompanyNumber
        .OrganisationName = WizardFinishParameters.OrganisationName
        .FirstName = WizardFinishParameters.FirstName
        .LastName = WizardFinishParameters.LastName
        .DateOfBirth = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(WizardFinishParameters.DateOfBirth)

        If Len(WizardFinishParameters.SecurityRegisterSearchCollateralType) &lt;&gt; 0 Then
          .SecurityRegisterSearchCollateralType = finBL.Enums.iseSecurityRegisterSearchCollateralType_FromString(WizardFinishParameters.SecurityRegisterSearchCollateralType)
        End If

        If WizardFinishParameters.GrantorPMSI Then
          .PmsiCriteria = iseSecurityRegisterSearchPMSI.Pmsi
        ElseIf WizardFinishParameters.GrantorPMSIBoth Then
          .PmsiCriteria = iseSecurityRegisterSearchPMSI.Both
        ElseIf WizardFinishParameters.GrantorNonPMSI Then
          .PmsiCriteria = iseSecurityRegisterSearchPMSI.NonPmsi
        End If

        .TransitionalCriteria(0) = WizardFinishParameters.GrantorNonTransitional
        .TransitionalCriteria(1) = WizardFinishParameters.GrantorTransitionalNonMigrated
        .TransitionalCriteria(2) = WizardFinishParameters.GrantorTransitionalMigrated
        .DateGrantorFrom = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(WizardFinishParameters.DateGrantorFrom)
        .DateGrantorTo = finBL.HtmlWidgetUtilities.GetDatabaseDateFromJsonUtcDate(WizardFinishParameters.DateGrantorTo)

        ' Serial Number
        If Len(WizardFinishParameters.SerialNumberType) &lt;&gt; 0 Then
          .SerialNumberType = finBL.Enums.iseRegisterSerialNumberType_FromString(WizardFinishParameters.SerialNumberType)
        End If
        .SerialNumber = WizardFinishParameters.SerialNumber
      End With

      ' Set Log Subject
      LogSubject = String.Format("PPSR B2G {0} Search", Request.SearchTypeText)
    End If

    ' Perform Search
    If Success Then
      If finBL.SecurityRegister.ExecuteG2BSearchFs(Request, Response, ServiceLogCreateDetails, Errors) Then
        If Errors Is Nothing Then
          ServiceLogPk = ServiceLogCreateDetails.ServiceLogPk
        Else
          Success = False
          finBL.Error.ErrorBegin(Errors.ToStringFormatted())
        End If
      Else
        Success = False
      End If
    End If

    ' Create Log
    If Success Then
      Select Case Request.SearchType
        Case iseSecurityRegisterSearchType.Aircraft, iseSecurityRegisterSearchType.IntellectualProperty, iseSecurityRegisterSearchType.MotorVehicle, iseSecurityRegisterSearchType.Watercraft
          ' Aircraft / Motor Vehicle - Security Statement / Item Log
          If Len(mAccountAppId) &lt;&gt; 0 Then
            ' Account Application
            AccountAppLog = finBL.CreateAccountAppLog()
            With AccountAppLog
              ' Set Properties
              .AccountAppId = mAccountAppId
              .AccountAppApplicantPk = mAccountAppApplicantPk
              .AccountAppCollateralItemPk = mAccountAppCollateralPk
              .LogType = isefinLogType.Service
              .SourceSet(isefinLogSource.UserInterface)
              .Subject = LogSubject
              .Notes = Request.SearchCriteria
              .ServiceLogPk = ServiceLogCreateDetails.ServiceLogPk

              ' Workflow
              .WorkflowPk = mWorkflowPk
              .WorkflowItemPk = mWorkflowItemPk

              ' Save
              Success = .Save()
            End With
          ElseIf mSecurityStmtItemPk &lt;&gt; 0 Then
            ' Security Statement Item Log
            SecurityStmtItemLog = finBL.CreateSecurityStmtItemLog()
            With SecurityStmtItemLog
              ' Set Properties
              .SecurityStmtItemPk = mSecurityStmtItemPk
              .LogType = isefinLogType.Service
              .SourceSet(isefinLogSource.UserInterface)
              .Subject = LogSubject
              .Notes = Request.SearchCriteria
              .ServiceLogPk = ServiceLogCreateDetails.ServiceLogPk

              ' Workflow
              .WorkflowPk = mWorkflowPk
              .WorkflowItemPk = mWorkflowItemPk

              ' Save
              Success = .Save()
            End With
          ElseIf Len(mSecurityStmtId) &lt;&gt; 0 Then
            ' Security Statement Log
            SecurityStmtLog = finBL.CreateSecurityStmtLog()
            With SecurityStmtLog
              ' Set Properties
              .SecurityStmtId = mSecurityStmtId
              .LogType = isefinLogType.Service
              .SourceSet(isefinLogSource.UserInterface)
              .Subject = LogSubject
              .Notes = Request.SearchCriteria
              .ServiceLogPk = ServiceLogCreateDetails.ServiceLogPk

              ' Workflow
              .WorkflowPk = mWorkflowPk
              .WorkflowItemPk = mWorkflowItemPk

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

        Case iseSecurityRegisterSearchType.DebtorOrganisation, iseSecurityRegisterSearchType.DebtorOrganisationDateRange, iseSecurityRegisterSearchType.DebtorPerson, iseSecurityRegisterSearchType.DebtorPersonDateRange
          If Len(mAccountAppId) &lt;&gt; 0 Then
            ' Account Application
            AccountAppLog = finBL.CreateAccountAppLog()
            With AccountAppLog
              ' Set Properties
              .AccountAppId = mAccountAppId
              .AccountAppApplicantPk = mAccountAppApplicantPk
              .AccountAppCollateralItemPk = mAccountAppCollateralPk
              .LogType = isefinLogType.Service
              .SourceSet(isefinLogSource.UserInterface)
              .Subject = LogSubject
              .Notes = Request.SearchCriteria
              .ServiceLogPk = ServiceLogCreateDetails.ServiceLogPk

              ' Workflow
              .WorkflowPk = mWorkflowPk
              .WorkflowItemPk = mWorkflowItemPk

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

          ' Client
          If Len(mClientId) &lt;&gt; 0 Then
            ClientLog = finBL.CreateClientLog()
            With ClientLog
              ' Set Properties
              .ClientId = mClientId
              .LogType = isefinLogType.Service
              .SourceSet(isefinLogSource.UserInterface)
              .Subject = LogSubject
              .Notes = Request.SearchCriteria
              .ServiceLogPk = ServiceLogCreateDetails.ServiceLogPk

              ' Workflow
              .WorkflowPk = mWorkflowPk
              .WorkflowItemPk = mWorkflowItemPk

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

    ' Action Workflow Item
    If Success AndAlso mWorkflowPk &lt;&gt; 0 Then
      finBL.HtmlWidgetUtilities.WorkflowItemComplete(mStartupParameters, Warning)

      If Len(Warning) &lt;&gt; 0 Then
        Warning = "The PPSR B2G Search completed successfully, however the Workflow Item could not be actioned due to the following error:" &amp; vbNewLine &amp; vbNewLine &amp; Warning
      End If
    End If
  Else
    ServiceLogPk = WizardFinishParameters.ServiceLogPk
  End If

  ' Return Search Results
  If Success Then
    Success = GetSearchResults(ServiceLogPk, returnValue)
  End If

  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; "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 ConfirmList As List(Of String)
  Dim Data As Object
  Dim FailedControlId As String
  Dim FailedMessage As String
  Dim PageId As String
  Dim strTemp 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

  ' Initialise
  ConfirmList = New List(Of String)

  ' Validate Page
  Select Case PageId
    Case "General"
      ' Deserialise
      Success = GetWizardFinishParameters(parametersJson, WizardFinishParameters)

      ' Search By
      If Success Then
        Select Case finBL.Enums.iseSecurityRegisterSearchType_FromString(WizardFinishParameters.SearchType)
          Case iseSecurityRegisterSearchType.MotorVehicle
            ' Motor Vehicle
            If finBL.Enums.iseRegisterSerialNumberType_FromString(WizardFinishParameters.SerialNumberType) = iseRegisterSerialNumberType.AU_MotorVehicle_VIN Then
              If Not finBL.CurrentCountry.ValidateVIN(WizardFinishParameters.SerialNumber, "", strTemp) Then
                ConfirmList.Add(strTemp)
              End If
            End If
        End Select
      End If

      Data = ConfirmList
  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;
'''  Client AKA.
''' &lt;/summary&gt;
Public Class ClientAka

  Public DateOfBirth As Date?
  Public GivenNames As String
  Public LastName As String
  Public Name As String
  Public Notes As String
  Public Title As String
  Public OrganisationType As String
  Public OrganisationNumber As String
  Public OrganisationName As String
  Public IsOrganisation As Boolean

  Public Sub New(firstName As String,
                 lastName As String,
                 middleNames As String,
                 notes As String,
                 title As String,
                 dateOfBirth As Date)

    Me.DateOfBirth = finBLShared.HtmlWidgetUtilities.GetNullableJsonUtcDateFromDatabaseDate(dateOfBirth)
    Me.GivenNames = finBLShared.Runtime.TextUtilities.ListSeparate(" ", firstName, middleNames)
    Me.LastName = lastName
    Me.Notes = notes
    Me.Title = title
    Me.IsOrganisation = False

  End Sub

  Public Sub New(name As String,
                 notes As String,
                 businessNumber As String,
                 organisationNumber As String,
                 clientClass As finClientClass)

    Me.Name = name
    Me.Notes = notes
    Me.IsOrganisation = True

    ' Defaults for Organisation Type &amp; Number / Name
    Me.OrganisationName = name
    Me.OrganisationType = "Organisation Name"
    Select Case clientClass.ClientClassBase
      Case iseClientClassBase.SoleTrader
        ' Could be with ABN or without ABN
        If Len(businessNumber) &lt;&gt; 0 Then
          Me.OrganisationNumber = businessNumber
          Me.OrganisationType = clientClass.BusinessNumberAbbrev
        End If

      Case iseClientClassBase.Trust
        ' Could have an ACN or an ABN
        If Len(organisationNumber) &lt;&gt; 0 Then
          Me.OrganisationNumber = organisationNumber
          Me.OrganisationType = clientClass.CompanyNumberAbbrev
        ElseIf Len(businessNumber) &lt;&gt; 0 Then
          Me.OrganisationNumber = businessNumber
          Me.OrganisationType = clientClass.BusinessNumberAbbrev
        End If

      Case Else
        If clientClass.HasCompanyNumber AndAlso Len(organisationNumber) &lt;&gt; 0 Then
          Me.OrganisationNumber = organisationNumber
          Me.OrganisationType = clientClass.CompanyNumberAbbrev
        ElseIf clientClass.HasBusinessNumber AndAlso Len(businessNumber) &lt;&gt; 0 Then
          Me.OrganisationNumber = businessNumber
          Me.OrganisationType = clientClass.BusinessNumberAbbrev
        End If
    End Select

  End Sub

End Class



''' &lt;summary&gt;
'''  Wizard Initialisation Information.
''' &lt;/summary&gt;
Public Class FormInitialisationInfo

  ' Record
  Public AccountAppApplicantPk As Integer
  Public AccountAppCollateralItemPk As Integer
  Public AccountAppId As String
  Public AccountAppName As String
  Public ClientAkas As List(Of ClientAka)
  Public ClientId As String
  Public ClientName As String
  Public RunFromServiceLog As Boolean
  Public SearchFromDefaultDate As Date
  Public SearchResultsJson As String
  Public SecurityStmtDescription As String
  Public SecurityStmtId As String
  Public SecurityStmtItemPk As Integer
  Public ServiceLogCaption As String
  Public WorkflowDescription As String
  Public WorkflowId As String

  ' Lists
  Public GrantorCollateralTypeDefault As String
  Public GrantorCollateralTypes As String
  Public OrganisationTypes As String
  Public SearchTypes As Object
  Public SerialNumberSearchTypes As New List(Of SerialNumberSearchType)
  Public SecurityItems As New List(Of SecurityItem)

  ' Configuration
  Public CanViewServiceLog As Boolean
  Public FormHeading As String
  Public IsAdministrator As Boolean
  Public ShowRequestResponseXml As Boolean
  Public TestMode As Boolean

End Class



''' &lt;summary&gt;
'''  Previous Search Result.
''' &lt;/summary&gt;
Public Class PreviousSearchResult

  Public [Date] As Date
  Public BillingNumber As String
  Public BillingReference As String
  Public Errors As String
  Public HasErrors As Boolean
  Public Request As String
  Public ResultCount As Integer
  Public SearchCriteria As String
  Public SearchId As String
  Public SearchType As String
  Public ServiceLogPk As Integer
  Public UserId As String
  Public UserPk As Integer

  Public Sub New(securityRegisterPreviousSearch As finSecurityRegisterPreviousSearch)

    With securityRegisterPreviousSearch
      Me.Date = finBLShared.HtmlWidgetUtilities.GetJsonUtcDateTimeFromDatabaseDateTime(.Date)
      Me.BillingNumber = .BillingTxnNumber
      Me.BillingReference = .BillingReference
      Me.Errors = .ErrorsDescription
      Me.HasErrors = .HasErrors
      Me.Request = .SearchCriteria
      Me.ResultCount = .ResultCount
      Me.SearchCriteria = .SearchCriteria
      Me.SearchId = .SearchId
      Me.SearchType = .SearchTypeText
      Me.ServiceLogPk = .ServiceLogPk
      Me.UserId = finBLShared.Users.ItemByPkSafe(.UserPk).UserId
      Me.UserPk = .UserPk
    End With

  End Sub

End Class



''' &lt;summary&gt;
'''  Security Item.
''' &lt;/summary&gt;
Public Class SecurityItem

  Public DefaultSerialNumberType As String
  Public Description As String
  Public SearchType As String
  Public SecurityItemDefaults As New List(Of SecurityItemDefault)

  ''' &lt;summary&gt;
	'''  Account Application Collateral Item.
	''' &lt;/summary&gt;
  Public Sub New(collateralItem As finAccountAppCollateralItem)

    Dim List As ISList
    Dim strTemp As String

    Me.Description = collateralItem.Description

    Select Case collateralItem.SecurityType.BaseType
      Case isefinSecurityBaseType.Aircraft
        ' --------
        ' Aircraft
        ' --------
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Aircraft)
        With collateralItem
          ' Manufacturer Serial Number
          If Len(.ManufacturerSerialNumber) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Aircraft_AirframeManufacturersNumber)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Aircraft_AirframeManufacturersNumber, .ManufacturerSerialNumber))
          End If

          ' Registration Mark
          If Len(.RegistrationMark) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Aircraft_NationalityCodeRegistrationMark)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Aircraft_NationalityCodeRegistrationMark, .RegistrationMark))
          End If
        End With

      Case isefinSecurityBaseType.Boat
        ' ----
        ' Boat
        ' ----
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Watercraft)
        With collateralItem
          ' HIN
          If Len(.HIN) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Watercraft_HIN)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Watercraft_HIN, .HIN))
          End If

          ' Offical Number
          If Len(.IdentificationNumber) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Watercraft_OfficialNumber)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Watercraft_OfficialNumber, .IdentificationNumber))
          End If
        End With

      Case isefinSecurityBaseType.SerialNumberedGood
        ' --------------------------------------------
        ' Serial Numbered Good (Intellectual Property)
        ' --------------------------------------------
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.IntellectualProperty)
        With collateralItem
          ' Serial Number
          If Len(.SerialNumber) &lt;&gt; 0 Then
            ' All Serial Number Types for Intellectual Property use the same serial number
            List = finBLShared.Enums.iseRegisterSerialNumberType_GetList(iseSecurityRegisterSearchType.IntellectualProperty)
            For Each strTemp In List
              Me.SecurityItemDefaults.Add(New SecurityItemDefault(finBLShared.Enums.iseRegisterSerialNumberType_FromString(strTemp), .SerialNumber))
            Next
          End If
        End With

      Case isefinSecurityBaseType.MotorVehicle
        ' -------------
        ' Motor Vehicle
        ' -------------
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.MotorVehicle)
        With collateralItem
          ' Manufacturer Serial Number
          If Len(.ManufacturerSerialNumber) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_MotorVehicle_ManufacturersNumber)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_MotorVehicle_ManufacturersNumber, .ManufacturerSerialNumber))
          End If

          ' Chassis
          If Len(.Chassis) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_MotorVehicle_Chassis)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_MotorVehicle_Chassis, .Chassis))
          End If

          ' VIN
          If Len(.VIN) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_MotorVehicle_VIN)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_MotorVehicle_VIN, .VIN))
          End If
        End With
    End Select

  End Sub

  ''' &lt;summary&gt;
	'''  Security Statement Item
	''' &lt;/summary&gt;
  Public Sub New(securityStmtItemBase As finSecurityStmtItemBase)

    Dim List As ISList
    Dim strTemp As String

    Me.Description = securityStmtItemBase.Description

    Select Case securityStmtItemBase.SecurityType.BaseType
      Case isefinSecurityBaseType.Aircraft
        ' --------
        ' Aircraft
        ' --------
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Aircraft)
        With securityStmtItemBase.ItemAsAircraft
          ' Manufacturer Serial Number
          If Len(.ManufacturerSerialNumber) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Aircraft_AirframeManufacturersNumber)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Aircraft_AirframeManufacturersNumber, .ManufacturerSerialNumber))
          End If

          ' Registration Mark
          If Len(.RegistrationMark) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Aircraft_NationalityCodeRegistrationMark)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Aircraft_NationalityCodeRegistrationMark, .RegistrationMark))
          End If
        End With

      Case isefinSecurityBaseType.Boat
        ' ----
        ' Boat
        ' ----
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.Watercraft)
        With securityStmtItemBase.ItemAsBoat
          ' HIN
          If Len(.HIN) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Watercraft_HIN)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Watercraft_HIN, .HIN))
          End If

          ' Offical Number
          If Len(.IdentificationNumber) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_Watercraft_OfficialNumber)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_Watercraft_OfficialNumber, .IdentificationNumber))
          End If
        End With

      Case isefinSecurityBaseType.SerialNumberedGood
        ' --------------------------------------------
        ' Serial Numbered Good (Intellectual Property)
        ' --------------------------------------------
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.IntellectualProperty)
        With securityStmtItemBase.ItemAsSerialNumberedGood
          ' Serial Number
          If Len(.SerialNumber) &lt;&gt; 0 Then
            ' All Serial Number Types for Intellectual Property use the same serial number
            List = finBLShared.Enums.iseRegisterSerialNumberType_GetList(iseSecurityRegisterSearchType.IntellectualProperty)
            For Each strTemp In List
              Me.SecurityItemDefaults.Add(New SecurityItemDefault(finBLShared.Enums.iseRegisterSerialNumberType_FromString(strTemp), .SerialNumber))
            Next
          End If
        End With

      Case isefinSecurityBaseType.MotorVehicle
        ' -------------
        ' Motor Vehicle
        ' -------------
        Me.SearchType = finBLShared.Enums.iseSecurityRegisterSearchType_ToString(iseSecurityRegisterSearchType.MotorVehicle)
        With securityStmtItemBase.ItemAsMotorVehicle
          ' Manufacturer Serial Number
          If Len(.ManufacturerSerialNumber) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_MotorVehicle_ManufacturersNumber)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_MotorVehicle_ManufacturersNumber, .ManufacturerSerialNumber))
          End If

          ' Chassis
          If Len(.Chassis) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_MotorVehicle_Chassis)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_MotorVehicle_Chassis, .Chassis))
          End If

          ' VIN
          If Len(.VIN) &lt;&gt; 0 Then
            Me.DefaultSerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(iseRegisterSerialNumberType.AU_MotorVehicle_VIN)
            Me.SecurityItemDefaults.Add(New SecurityItemDefault(iseRegisterSerialNumberType.AU_MotorVehicle_VIN, .VIN))
          End If
        End With
    End Select

  End Sub

End Class



''' &lt;summary&gt;
'''  Represents a default value for each Serial Number Type
''' &lt;/summary&gt;
Public Class SecurityItemDefault

  Public SerialNumberType As String
  Public Value As String

  Public Sub New(registerSerialNumberType As iseRegisterSerialNumberType,
                 value As String)

    Me.SerialNumberType = finBLShared.Enums.iseRegisterSerialNumberType_ToString(registerSerialNumberType)
    Me.Value = value

  End Sub

End Class



''' &lt;summary&gt;
'''  Serial Number Search Type.
''' &lt;/summary&gt;
Public Class SerialNumberSearchType

  Public Code As String
  Public ListCsv As String
  Public Tooltip As String

  Public Sub New(searchType As iseSecurityRegisterSearchType)

    Me.Code = searchType.ToString()
    Me.ListCsv = finBLShared.Enums.iseRegisterSerialNumberType_GetList(searchType).ToCsvString()

    Select Case searchType
      Case iseSecurityRegisterSearchType.Aircraft
        Me.Tooltip = "For 'Nationality Code and Registration Mark' enter both Nationality Code and Registration Mark, e.g. VH-XYZ." &amp; vbNewLine &amp; "For 'Manufacturers Number' Serial Number Types enter all characters including leading zeros."

      Case iseSecurityRegisterSearchType.IntellectualProperty
        Me.Tooltip = "Enter the number as issued by the issuing body."

      Case iseSecurityRegisterSearchType.MotorVehicle
        Me.Tooltip = "For 'VIN' enter 17 characters."

      Case iseSecurityRegisterSearchType.Watercraft
        Me.Tooltip = "'HIN' is also used for migrated outboard motor engine numbers." &amp; vbNewLine &amp; "For 'Official Number' include leading zeros to make the full 6 characters (do not enter the 'ON' prefix)."
    End Select

  End Sub

End Class



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

  Public Data As Object
  Public FailedControlId As String
  Public FailedMessage 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



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

  ' General
  Public SecurityItemDescription As String
  Public ServiceLogPk As Integer

  ' Search
  Public AcceptDeclaration As Boolean
  Public BillingReference As String
  Public SearchType As String

  ' Financing Statement
  Public FinancingStatementId As String
  Public FinancingStatementIncludeHistory As Boolean

  ' Debtor Search
  Public OrganisationType As String
  Public CompanyNumber As String
  Public OrganisationName As String
  Public FirstName As String
  Public LastName As String
  Public DateOfBirth As Date?
  Public SecurityRegisterSearchCollateralType As String
  Public GrantorPMSI As Boolean
  Public GrantorPMSIBoth As Boolean
  Public GrantorNonPMSI As Boolean
  Public GrantorNonTransitional As Boolean
  Public GrantorTransitionalNonMigrated As Boolean
  Public GrantorTransitionalMigrated As Boolean
  Public DateGrantorFrom As Date?
  Public DateGrantorTo As Date?

  ' Serial Number
  Public SerialNumberType As String
  Public SerialNumber As String

End Class</Code>
    <Language>VisualBasic</Language>
    <Notes>System defined HTML Widget.

Used as a finPOWER Connect Cloud compatible version of the "PPSRB2GAUSearch" form.</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;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="Select the type of search to perform."&gt;PPSR B2G Search&lt;/li&gt;
        &lt;li tabId="PreviousSearch" tooltipText="Load Previous Searches."&gt;Previous Search&lt;/li&gt;
        &lt;li tabId="DebtorSearch" tooltipText="Enter Client Details."&gt;Debtor Search&lt;/li&gt;
        &lt;li tabId="SearchResults" tooltipText="Search Results."&gt;Summary&lt;/li&gt;
        &lt;li tabId="SearchCriteria" tooltipText="No Registrations were returned in this Search."&gt;Search Criteria&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" style="display:flex;flex-direction:column;"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:10em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;!-- Workflow --&gt;
        &lt;tbody id="tbWorkflow"&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;/tbody&gt;

        &lt;!-- Client --&gt;
        &lt;tbody id="tbClient"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblClient"&gt;Client details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboClient"&gt;Client:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboClient" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Security Statement --&gt;
        &lt;tbody id="tbSecurityStmt"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblSecurityStmt"&gt;Security details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboSecurityStmt"&gt;Security:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboSecurityStmt" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboSecurityStmtItem"&gt;Item:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboSecurityStmtItem" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Search Type --&gt;
        &lt;tbody&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblSearchType"&gt;Select the Search type&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboSearchType"&gt;Search Type:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboSearchType" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Billing Reference --&gt;
        &lt;tbody&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblBillingReference"&gt;Enter Reference details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtBillingReference"&gt;Billing Reference:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtBillingReference" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Declaration --&gt;
        &lt;tbody id="tbDeclaration"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblDeclaration"&gt;Declaration&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td colspan="2"&gt;&lt;label id="lblDeclarationText"&gt;I declare that I have accepted the PPSR Conditions of Use and am undertaking the search for an authorised purpose.&lt;/label&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkDeclaration" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Aircraft / Motor Vehicle / Watercraft Serial Number Search Type --&gt;
        &lt;tbody id="tbSerialNumberSearchType"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblSerialNumberSearchType"&gt;Select the Serial Number search type and enter the Serial Number&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboSerialNumberType"&gt;Serial&amp;nbsp;Number&amp;nbsp;Type:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboSerialNumberType" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtSerialNumber"&gt;Serial Number:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtSerialNumber" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Financing Statement --&gt;
        &lt;tbody id="tbFinancingStatement"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblFinancingStatement"&gt;Enter the collateral Registration Number&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtFinancingStatement"&gt;Registration&amp;nbsp;No.:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtFinancingStatement" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblChangeHistory"&gt;View the change history for the Registration&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkFinancingStatementIncludeHistory" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Client AKAs --&gt;
        &lt;tbody id="tbClientAka"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblClientAka"&gt;Also Known As&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;

      &lt;!-- Client AKAs --&gt;
      &lt;div style="flex-grow:1;position:relative;margin-top:8px;"&gt;
        &lt;div id="gridClientAka" class="is-dock-fill"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;



    &lt;!-- Previous Search --&gt;
    &lt;div id="pagePreviousSearch" style="display:flex;flex-direction:column;"&gt;
      &lt;!-- Filters --&gt;
      &lt;div&gt;
        &lt;table class="is-form"&gt;
          &lt;colgroup&gt;
            &lt;col /&gt;
          &lt;/colgroup&gt;

          &lt;tr&gt;
            &lt;th&gt;&lt;label id="lblSearchDates"&gt;Select the Search dates for filtering&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;
              From:&amp;nbsp;&lt;input id="dateSearchFrom" /&gt;
              &amp;nbsp;to:&amp;nbsp;&lt;input id="dateSearchTo" /&gt;
            &lt;/th&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th&gt;&lt;label id="lblAllUsers"&gt;Show Searches Performed by all Users or the current User&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;input id="chkOptionsAllUsers" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label id="lblIncludeError"&gt;Include Searches that returned errors from the PPSR&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;input id="chkOptionsIncludeErrors" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;button id="cmdLoadPreviousSearches" class="is-button ok"&gt;Load&lt;/button&gt; &lt;div id="divSearchInformation" class="is-info-text info small" style="display:none"&gt;&lt;/div&gt;&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/div&gt;

      &lt;!-- Previous Searches --&gt;
      &lt;div style="flex-grow:1;position:relative;margin-top:8px;"&gt;
        &lt;div id="gridPreviousSearches" class="is-dock-fill"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;



    &lt;!-- Debtor Search --&gt;
    &lt;div id="pageDebtorSearch"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;!-- Individual --&gt;
        &lt;tbody id="tbIndividualClient"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblPersonsDetails"&gt;Persons Details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtGivenNames"&gt;Given Names:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtGivenNames" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtLastName"&gt;Last Name:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtLastName" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="dateDateOfBirth"&gt;Date of Birth:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="dateDateOfBirth" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;!-- Organisation --&gt;
        &lt;tbody id="tbOrganisationClient"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblOrganisationDetails"&gt;Organisation's Details&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboOrganisationType"&gt;Search:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboOrganisationType" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtOrganisationNumber"&gt;Number:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtOrganisationNumber" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="txtOrganisationName"&gt;Name:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="txtOrganisationName" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;tbody id="tbDebtorOtherOptions"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblCollateralType"&gt;Select Collateral Type.&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="cboCollateralType"&gt;Collateral:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="cboCollateralType" /&gt;&lt;/td&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblPmsi"&gt;Select Purchase Money Security Interest (PMSI) criteria&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;div id="rblPmsi"&gt;&lt;/div&gt;&lt;/th&gt;
          &lt;/tr&gt;

          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblGrantorTransitional"&gt;Select Transitional Registration criteria&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkGrantorNonTransitional" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkGrantorTransitionalNonMigrated" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;input id="chkGrantorTransitionalMigrated" type="checkbox" /&gt;&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;

        &lt;tbody id="tbDebtorDateRange"&gt;
          &lt;tr&gt;
            &lt;th colspan="2"&gt;&lt;label id="lblDebtorDateRange"&gt;Select the dates for searching registration events (dates specified in Canberra time)&lt;/label&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;th&gt;&lt;label for="dateDebtorFrom"&gt;From:&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;&lt;input id="dateDebtorFrom" /&gt;&amp;nbsp;&amp;nbsp;to&amp;nbsp;&amp;nbsp;&lt;input id="dateDebtorTo" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Search Results --&gt;
    &lt;div id="pageSearchResults"&gt;
      &lt;div class="is-dock-fill is-split-container split5050"&gt;
        &lt;div class="panel"&gt;
          &lt;div id="gridSearchResults"&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="panel"&gt;
          &lt;div id="wbSearchResult" class="is-dock-fill"&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;



    &lt;!-- Search Criteria --&gt;
    &lt;div id="pageSearchCriteria"&gt;
      &lt;div id="wbSearchCriteria" class="is-dock-fill"&gt;&lt;/div&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="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;
// Properties
var mRecord;
var mRecord_ClientAkas;
var mRecord_SecurityItems;
var mRecord_SerialNumberSearchTypes;

var mSearchType;
var mSearchResults;
var mPreviousSearchResults;

// Controls
var C = {
  //   General
  tbWorkflow: null,
  lblWorkflow: null,
  cboWorkflow: null,

  tbClient: null,
  lblClient: null,
  cboClient: null,

  tbSecurityStmt: null,
  lblSecurityStmt: null,
  cboSecurityStmt: null,
  cboSecurityStmtItem: null,

  lblSearchType: null,
  cboSearchType: null,

  lblBillingReference: null,
  txtBillingReference: null,

  tbDeclaration: null,
  lblDeclaration: null,
  lblDeclarationText: null,
  chkDeclaration: null,

  tbSerialNumberSearchType: null,
  lblSerialNumberSearchType: null,
  cboSerialNumberType: null,
  txtSerialNumber: null,

  tbFinancingStatement: null,
  lblFinancingStatement: null,
  txtFinancingStatement: null,
  lblChangeHistory: null,
  chkFinancingStatementIncludeHistory: null,

  tbClientAka: null,
  lblClientAka: null,
  gridClientAka: null,

  //   Previous Searches
  lblSearchDates: null,
  dateSearchFrom: null,
  dateSearchTo: null,

  lblAllUsers: null,
  chkOptionsAllUsers: null,
  lblIncludeError: null,
  chkOptionsIncludeErrors: null,

  divSearchInformation: null,

  gridPreviousSearches: null,

  //   Debtor Search
  tbIndividualClient: null,
  lblPersonsDetails: null,
  txtGivenNames: null,
  txtLastName: null,
  dateDateOfBirth: null,

  tbOrganisationClient: null,
  lblOrganisationDetails: null,
  cboOrganisationType: null,
  txtOrganisationNumber: null,
  txtOrganisationName: null,

  tbDebtorOtherOptions: null,
  lblCollateralType: null,
  cboCollateralType: null,

  lblPmsi: null,
  rblPmsi: null,

  lblGrantorTransitional: null,
  chkGrantorNonTransitional: null,
  chkGrantorTransitionalNonMigrated: null,
  chkGrantorTransitionalMigrated: null,

  tbDebtorDateRange: null,
  lblDebtorDateRange: null,
  dateDebtorFrom: null,
  dateDebtorTo: null,

  //   Search Results
  gridSearchResults: null,
  wbSearchResult: null,

  //   Search Criteria
  wbSearchCriteria: null,
}

// Form
var frmMain;
var tabWizard;

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

var cmdLoadPreviousSearches;

// Other
var mDeclarationVisible = false;
var mLastFinishParametersJson = "";
var mPreviousSearchServiceLogPk;
var mShowNoResultsInModalWindow = false;

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

  // Controls
  //   General
  C.tbWorkflow = $("#tbWorkflow");
  C.lblWorkflow = widget.UI.Label("lblWorkflow", {});
  C.cboWorkflow = widget.UI.DBCombo("cboWorkflow", {
    readOnly: true,
    showDropdown: false,
  });

  C.tbClient = $("#tbClient");
  C.lblClient = widget.UI.Label("lblClient", {});
  C.cboClient = widget.UI.DBCombo("cboClient", {
    readOnly: true,
    showDropdown: false,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });

  C.tbSecurityStmt = $("#tbSecurityStmt");
  C.lblSecurityStmt = widget.UI.Label("lblSecurityStmt", {});
  C.cboSecurityStmt = widget.UI.DBCombo("cboSecurityStmt", {
    readOnly: true,
    showDropdown: false,
    width: widget.UI.FIELD_WIDTH_CODE_10,
  });
  C.cboSecurityStmtItem = widget.UI.ComboBox("cboSecurityStmtItem", {
    limitToList: true,
    maxLength: 50,

    onChange: cboSecurityStmtItem_Change,
  });

  C.lblSearchType = widget.UI.Label("lblSearchType", {});
  C.cboSearchType = widget.UI.ComboBox("cboSearchType", {
    allowBlank: false,
    maxLength: 30,

    onChange: cboSearchType_Change,
  });

  C.lblBillingReference = widget.UI.Label("lblBillingReference", {});
  C.txtBillingReference = widget.UI.TextBox("txtBillingReference", {
    maxLength: 30,
  });

  C.tbDeclaration = $("#tbDeclaration");
  C.lblDeclaration = widget.UI.Label("lblDeclaration", {});
  C.lblDeclarationText = widget.UI.Label("lblDeclarationText", {
    style: "normal"
  });
  C.chkDeclaration = widget.UI.CheckBox("chkDeclaration", {
    caption: "I agree",
    captionWrap: true,

    onChange: chkDeclaration_Change,
  });

  C.tbSerialNumberSearchType = $("#tbSerialNumberSearchType");
  C.lblSerialNumberSearchType = widget.UI.Label("lblSerialNumberSearchType", {});
  C.cboSerialNumberType = widget.UI.ComboBox("cboSerialNumberType", {
    allowBlank: false,
    limitToList: true,
    maxLength: 50,

    onChange: cboSerialNumberType_Change,
  });
  C.txtSerialNumber = widget.UI.TextBox("txtSerialNumber", {
    allowBlank: false,
    maxLength: 50,
  });

  C.tbFinancingStatement = $("#tbFinancingStatement");
  C.lblFinancingStatement = widget.UI.Label("lblFinancingStatement", {});
  C.txtFinancingStatement = widget.UI.TextBox("txtFinancingStatement", {
    allowBlank: false,
    maxLength: 16,
  });
  C.lblChangeHistory = widget.UI.Label("lblChangeHistory", {});
  C.chkFinancingStatementIncludeHistory = widget.UI.CheckBox("chkFinancingStatementIncludeHistory", {
    caption: "Include earlier versions of the Registration?",
    captionWrap: true,
  });

  C.tbClientAka = $("#tbClientAka");
  C.lblClientAka = widget.UI.Label("lblClientAka", {
    tooltipText: "Select a row below to prepopulate details on the next page."
  });

  //   Previous Searches
  C.lblSearchDates = widget.UI.Label("lblSearchDates", {});
  C.dateSearchFrom = widget.UI.DateBox("dateSearchFrom", {});
  C.dateSearchTo = widget.UI.DateBox("dateSearchTo", {});

  C.lblAllUsers = widget.UI.Label("lblAllUsers", {});
  C.chkOptionsAllUsers = widget.UI.CheckBox("chkOptionsAllUsers", {
    caption: "All Users?",
    captionWrap: true,
  });
  C.lblIncludeError = widget.UI.Label("lblIncludeError", {});
  C.chkOptionsIncludeErrors = widget.UI.CheckBox("chkOptionsIncludeErrors", {
    caption: "Include Failed Searches?",
    captionWrap: true,
  });

  C.divSearchInformation = $("#divSearchInformation");

  //   Debtor Search
  C.tbIndividualClient = $("#tbIndividualClient");
  C.lblPersonsDetails = widget.UI.Label("lblPersonsDetails", {
    tooltipText: "Important: Enter the individual's name as shown on their driver's licence or as otherwise indicated in the grantor identification rules as specified in the PPS Regulations.\n\nOtherwise there is a risk that registrations against the grantor will not be found. The exact spelling of an individual's name is required."
  });
  C.txtGivenNames = widget.UI.TextBox("txtGivenNames", {
    allowBlank: false,
    maxLength: 50,
  });
  C.txtLastName = widget.UI.TextBox("txtLastName", {
    allowBlank: false,
    maxLength: 50,
  });
  C.dateDateOfBirth = widget.UI.DateBox("dateDateOfBirth", {
    allowBlank: false,
    historic: true,
    showAge: true,
  });

  C.tbOrganisationClient = $("#tbOrganisationClient");
  C.lblOrganisationDetails = widget.UI.Label("lblOrganisationDetails", {
    tooltipText: "The organisation identifier you are undertaking a search against must be in accordance with the grantor identification rules in the PPS Regulations.\nIf searching by Organisation Name, the exact spelling of the organisation's name is required.",
  });
  C.cboOrganisationType = widget.UI.ComboBox("cboOrganisationType", {
    allowBlank: false,
    limitToList: true,
    maxLength: 20,

    onChange: cboOrganisationType_Change,
  });
  C.txtOrganisationNumber = widget.UI.TextBox("txtOrganisationNumber", {
    allowBlank: false,
    maxLength: 20,
  });
  C.txtOrganisationName = widget.UI.TextBox("txtOrganisationName", {
    allowBlank: false,
    maxLength: 50,
  });

  C.tbDebtorOtherOptions = $("#tbDebtorOtherOptions");
  C.lblCollateralType = widget.UI.Label("lblCollateralType", {
    tooltipText: "All present and after-acquired property are always included in the search.",
  });
  C.cboCollateralType = widget.UI.ComboBox("cboCollateralType", {
    allowBlank: false,
    limitToList: true,
  });

  C.lblPmsi = widget.UI.Label("lblPmsi", {
    tooltipText: "For more information regarding Purchase Money Security Interests (PMSI), see the Australian Governments website:\nhttps://www.ppsr.gov.au/purchase-money-security-interests"
  });

  var list = [];
  list.push({ caption: "PMSI Registrations only", value: "PMSI" });
  list.push({ caption: "Non PMSI Registrations only", value: "NONPMSI" });
  list.push({ caption: "Both PMSI and non PMSI Registrations", value: "BOTH" });
  C.rblPmsi = widget.UI.RadioButtonList("rblPmsi", {
    allowBlank: false,
    layout: "vertical",
    list: list,
  });

  C.lblGrantorTransitional = widget.UI.Label("lblGrantorTransitional", {
    tooltipText: "For more information regarding Transitional Registrations, see the Australian Governments website:\nhttps://www.ppsr.gov.au/transitional-provisions",
  });
  C.chkGrantorNonTransitional = widget.UI.CheckBox("chkGrantorNonTransitional", {
    caption: "Not Transitional?",
    captionWrap: true,
  });
  C.chkGrantorTransitionalNonMigrated = widget.UI.CheckBox("chkGrantorTransitionalNonMigrated", {
    caption: "Transitional - Non Migrated?",
    captionWrap: true,
  });
  C.chkGrantorTransitionalMigrated = widget.UI.CheckBox("chkGrantorTransitionalMigrated", {
    caption: "Transitional - Migrated?",
    captionWrap: true,
  });

  C.tbDebtorDateRange = $("#tbDebtorDateRange");
  C.lblDebtorDateRange = widget.UI.Label("lblDebtorDateRange", {});
  C.dateDebtorFrom = widget.UI.DateBox("dateDebtorFrom", {
    allowBlank: false,
  });
  C.dateDebtorTo = widget.UI.DateBox("dateDebtorTo", {
    allowBlank: false,
  });

  //   Search Results
  C.wbSearchResult = widget.UI.PreviewPane("wbSearchResult", {
    formActionHandler: Widget_NotificationHandler,
  });

  //   Search Criteria
  C.wbSearchCriteria = widget.UI.PreviewPane("wbSearchCriteria", {});

  // Grids
  C.gridClientAka = widget.UI.Grid("gridClientAka", {
    stickyHeader: true,

    onInitialiseRow: gridClientAka_InitialiseRow,
    onRowDrilldown: gridClientAka_RowDrilldown,
  });
  C.gridPreviousSearches = widget.UI.Grid("gridPreviousSearches", {
    rowNumbering: true,
    stickyHeader: true,

    onInitialiseRow: gridPreviousSearches_InitialiseRow,
    onRowDrilldown: gridPreviousSearches_RowDrilldown,
  });
  C.gridSearchResults = widget.UI.Grid("gridSearchResults", {
    rowNumbering: true,
    stickyHeader: true,

    onAction: gridSearchResults_Action,
    onAfterRowActivate: gridSearchResults_AfterRowActivate,
    onInitialiseRow: gridSearchResults_InitialiseRow,
    onRowDrilldown: gridSearchResults_RowDrilldown,
  });

  // 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"); });

  cmdLoadPreviousSearches = $("#cmdLoadPreviousSearches");
  cmdLoadPreviousSearches.click(GetPreviousSearches);

  // Handle Notifications
  widget.DisableCloseButton();
  widget.ActionNotificationHandle(Widget_NotificationHandler);

  // Reset
  Form_Reset();
});

// ==========
// Reset Form
// ==========
function Form_Reset() {
  // Defaults
  C.chkOptionsIncludeErrors.Value(true);

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

  // Resize
  Form_Resize();

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

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

  mSearchResults = null;
  mPreviousSearchResults = [];
  mPreviousSearchServiceLogPk = 0;
  mShowNoResultsInModalWindow = false;

  // 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);
      mRecord_ClientAkas = mRecord.ClientAkas;
      mRecord_SecurityItems = mRecord.SecurityItems;
      mRecord_SerialNumberSearchTypes = mRecord.SerialNumberSearchTypes;

      // Give Collections ability to lookup by code
      widget.ArrayAllowLookupById(mRecord.SearchTypes, "Description");
      widget.ArrayAllowLookupById(mRecord_SerialNumberSearchTypes, "Code");

      // Load Fields
      Fields_Load();
    },

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

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.cboWorkflow.RefreshUnbound(mRecord.WorkflowId, mRecord.WorkflowDescription);
    C.cboClient.RefreshUnbound(mRecord.ClientId, mRecord.ClientName);
    C.cboSearchType.Text(mRecord.SearchByDefault);

    // Account Application or Security Statement
    if (mRecord.SecurityStmtId) {
      C.cboSecurityStmt.RefreshUnbound(mRecord.SecurityStmtId, mRecord.SecurityStmtDescription);
    }
    else if (mRecord.AccountAppId) {
      C.cboSecurityStmt.RefreshUnbound(mRecord.AccountAppId, mRecord.AccountAppName);
    }

    // Collateral Types
    C.cboCollateralType.Text(mRecord.GrantorCollateralTypeDefault);

    // Previous Searches
    C.dateSearchFrom.Value(mRecord.SearchFromDefaultDate);
  }

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

  // Update fields
  Fields_Update();

  // Update Controls
  cboOrganisationType_Change();

  // Refresh Tab
  tabWizard_Refresh();
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  // Not used by this HTML Widget
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    widget.SetHeading(mRecord.FormHeading);
  }

  // Information Lists

  // Lists
  if (mRecord) {
    // cboSecurityStmtItem
    C.cboSecurityStmtItem.ListFromCollection(mRecord_SecurityItems, "Description");
    if (mRecord_SecurityItems.length == 1) C.cboSecurityStmtItem.ListIndex(0);

    // cboSearchType
    C.cboSearchType.ListFromCodeDescriptionList(mRecord.SearchTypes);
    if (mRecord.SearchTypes.length == 1) {
      C.cboSearchType.ListIndex(0);
      C.cboSearchType.ReadOnly(true);
    }

    C.cboOrganisationType.ListFromCsvString(mRecord.OrganisationTypes);
    C.cboCollateralType.ListFromCsvString(mRecord.GrantorCollateralTypes);
  }

  // Controls
  if (mRecord) {
    if (!mRecord.WorkflowId) C.tbWorkflow.hide();
    if (!mRecord.ClientId) C.tbClient.hide();

    if ((!mRecord.SecurityStmtId &amp;&amp; !mRecord.AccountAppId) || mRecord.AccountAppApplicantPk) C.tbSecurityStmt.hide();
    if (mRecord.AccountAppId) C.cboSecurityStmt.Caption("Application:")

    C.cboSecurityStmtItem.ReadOnly(mRecord.SecurityStmtItemPk != 0 || mRecord.AccountAppCollateralItemPk != 0);

    // Previous Searches &amp; show all Users
    if (!mRecord.IsAdministrator) {
      C.lblAllUsers.VisibleRow(false);
      C.chkOptionsAllUsers.VisibleRow(false);
    }

    // Change Events
    cboSearchType_Change();
    cboSecurityStmtItem_Change();
  }

  // Auto-format
  tabWizard.AutoFormatPage();

  // Update Buttons
  tabWizard_UpdateButtons();

  // Read-Only?
  if (mRecord &amp;&amp; mRecord.ReadOnly) frmMain.FormReadOnly(C, true);

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

  // Resize Tab
  tabWizard_Resize();
}

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

  // Tab
  tabWizard_Resize();
}

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

function tabWizard_UpdateButtons() {
  var tabIndex = tabWizard.SelectedTabIndex();

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

  // Exceptions
  cmdCancel.hide();
  cmdFinish.text("Close");

  // Page Exceptions
  switch (tabWizard.SelectedTabId()) {
    case "PreviousSearch":
    case "SearchResults":
      cmdNext.prop("disabled", true);
      break;
  }

  // Service Log special mode
  if (mRecord.RunFromServiceLog) {
    cmdBack.hide();
    cmdNext.hide();
  }
}

// ==========
// Resize Tab
// ==========
function tabWizard_Resize() {
  switch (tabWizard.SelectedTabId()) {
    case "General":
      // General
      C.cboWorkflow.WidthResizeFromParent();
      C.cboClient.WidthResizeFromParent();
      C.cboSecurityStmt.WidthResizeFromParent();
      C.cboSecurityStmtItem.WidthResizeFromParent();

      C.txtBillingReference.WidthResizeFromParent();

      C.txtFinancingStatement.WidthResizeFromParent();
      break;

    case "DebtorSearch":
      // Debtor Search
      C.txtGivenNames.WidthResizeFromParent();
      C.txtLastName.WidthResizeFromParent();

      C.txtOrganisationNumber.WidthResizeFromParent();
      C.txtOrganisationName.WidthResizeFromParent();
      break;

    default:
      break;
  }
}

// ===========
// 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)) {
        case "PreviousSearch":
          found = (mSearchType.Code == "PreviousSearch");
          break;

        case "DebtorSearch":
          switch(mSearchType.Code) {
            case "DebtorOrganisation":
            case "DebtorOrganisationDateRange":
            case "DebtorPerson":
            case "DebtorPersonDateRange":
              found = true;
              break;

            default:
              found = false;
              break;
          }
          break;

        case "SearchResults":
          found = (tabWizard.SelectedTabId() != "SearchCriteria")
          break;

        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);
  }
}

// ===========
// Refresh Tab
// ===========
function tabWizard_Refresh(newTab) {
  // Moving forward onto tab, so Load information
  if (newTab &gt;= tabWizard.SelectedTabIndex()) {
    switch (tabWizard.GetTabIdByIndex(newTab)) {
      case "PreviousSearch":
        pagePreviousSearch_Refresh();
        break;

      case "DebtorSearch":
        pageDebtorSearch_Refresh();
        break;

      case "SearchResults":
        pageSearchResults_Refresh();
        break;

      case "SearchCriteria":
        pageSearchCriteria_Refresh();
        break;

      default:
        break;
    }
  }

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

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

  // Tweak fields
  // Jump to Results if Service Log has been specified
  if (mRecord.RunFromServiceLog) {
    // Jump to Search Results page
    tabWizard.SelectedTabId("SearchResults")

    // Populate Search Results
    PerformSearch_Done(mRecord.SearchResultsJson);
  }

  // Update Heading
  switch (tabWizard.SelectedTabId()) {
    default:
      if (mRecord.ServiceLogCaption) {
        frmMain.RefreshHeading("PPSR B2G Search Results", mRecord.ServiceLogCaption);
      }
      else {
        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;
  }
}

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

  // Other client-side validation
  if (Ok) {
    switch (tabWizard.SelectedTabId()) {
      case "General":
        // Declaration
        if (mDeclarationVisible &amp;&amp; !C.chkDeclaration.Value()) {
          Ok = false;
          widget.UI.MsgBoxAlert("You must agree to the declaration before continuing.");
        }
        break;

      case "DebtorSearch":
        // Transitional
        if (!C.chkGrantorNonTransitional.Value() &amp;&amp; !C.chkGrantorTransitionalNonMigrated.Value() &amp;&amp; !C.chkGrantorTransitionalMigrated.Value()) {
          Ok = false;
          widget.UI.MsgBoxAlert("Select at least one of the Transitional registration criteria.", { heading: "Invalid Transitional Criteria" });
        }
        break;

      case "PreviousSearch":
        if (C.gridPreviousSearches.ActiveDataRowIndex() &lt; 0) {
          Ok = false;
          widget.UI.MsgBoxAlert("At least one Previous Search must be selected to proceed.");
        }
        else {
          var item = mPreviousSearchResults[C.gridPreviousSearches.ActiveDataRowListIndex()];

          if (item.HasErrors) {
            // Do not proceed as there are errors
            Ok = false;
          }
          else {
            // Set Service Log Pk for results refresh
            mPreviousSearchServiceLogPk = item.ServiceLogPk;
          }
        }
        break;

      default:
        // No validation
        validCallback();
        return;
    }
  }

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

    switch (tabWizard.SelectedTabId()) {
      case "General":
        params = CreateFinishParameters();
        break;

      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);
    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":
        // General
        if (o.Data &amp;&amp; o.Data.length != 0) {
          // Confirm warnings
          widget.UI.MsgBoxConfirmList("To continue, please approve the following:",
                                      o.Data,
                                      {
                                        heading: "Additional Confirmation",
                                        icon: "Warning",
                                      },
                                      function () { validCallback(); },
                                      null);

          // Allow callbacks to continue
          return;
        };

        break;
    }

    // Callback
    validCallback();
  }
}

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

  // Enable form
  frmMain.FormEnable();
}

// ==================
// pagePreviousSearch
// ==================
function pagePreviousSearch_Refresh() {
  // Refresh Grid
  gridPreviousSearches_Refresh();

  // Populate Search Information if required
  var message = "";
  if (mRecord.ClientId) {
    // Client Id
    message = "Search results are limited to Client &lt;b&gt;" + widget.UI.HtmlEncode(mRecord.ClientId) + "&lt;/b&gt;, '" + widget.UI.HtmlEncode(mRecord.ClientName) + "'";

    // Account Application
    if (mRecord.AccountAppId) {
      message += " in the context of Account Application &lt;b&gt;" + widget.UI.HtmlEncode(mRecord.AccountAppId) + "&lt;/b&gt;, '" + widget.UI.HtmlEncode(mRecord.AccountAppName) + "'.";
    }
    else {
      message += ".";
    }
  }
  else if (mRecord.SecurityStmtId) {
    // Security Statement
    if (C.cboSecurityStmtItem.Text()) {
      message = "Search results are limited to Security Item &lt;b&gt;" + widget.UI.HtmlEncode(C.cboSecurityStmtItem.Text()) + "&lt;/b&gt; for Security Statement &lt;b&gt;" + widget.UI.HtmlEncode(mRecord.SecurityStmtId) + "&lt;/b&gt;, '" + widget.UI.HtmlEncode(mRecord.SecurityStmtDescription) + "'.";
    }
    else {
      message = "Search results are limited to Security Statement &lt;b&gt;" + widget.UI.HtmlEncode(mRecord.SecurityStmtId) + "&lt;/b&gt;, '" + widget.UI.HtmlEncode(mRecord.SecurityStmtDescription) + "'.";
    }
  }
  else if (mRecord.AccountAppId) {
    // Account Application
    if (C.cboSecurityStmtItem.Text()) {
      message = "Search results are limited to Collateral Item &lt;b&gt;" + widget.UI.HtmlEncode(C.cboSecurityStmtItem.Text()) + "&lt;/b&gt; for Account Application &lt;b&gt;" + widget.UI.HtmlEncode(mRecord.AccountAppId) + "&lt;/b&gt;, '" + widget.UI.HtmlEncode(mRecord.AccountAppName) + "'.";
    }
    else {
      message = "Search results are limited to Account Application &lt;b&gt;" + widget.UI.HtmlEncode(mRecord.AccountAppId) + "&lt;/b&gt;, '" + widget.UI.HtmlEncode(mRecord.AccountAppName) + "'.";
    }
  }

  // Show
  if (message) {
    C.divSearchInformation.html(message);
    C.divSearchInformation.show();
  }
  else {
    C.divSearchInformation.hide();
  }
}

// ================
// pageDebtorSearch
// ================
function pageDebtorSearch_Refresh() {
  var clientDetails;

  // Initialise
  C.tbIndividualClient.hide();
  C.tbOrganisationClient.hide();

  if (mRecord_ClientAkas) {
    // Get Client Details from loaded Client
    if (C.gridClientAka.ActiveDataRowIndex() == -1) {
      clientDetails = mRecord_ClientAkas[0];
    }
    else {
      clientDetails = mRecord_ClientAkas[C.gridClientAka.ActiveDataRowIndex()];
    }

    // Load Fields
    if (SearchTypeIsOrganisation()) {
      // Organisation
      C.cboOrganisationType.Text(clientDetails.OrganisationType);
      C.txtOrganisationNumber.Text(clientDetails.OrganisationNumber);
      C.txtOrganisationName.Text(clientDetails.OrganisationName);

      // Update Controls
      cboOrganisationType_Change();

      // Show
      C.tbOrganisationClient.show();
    }
    else {
      // Individual
      C.txtGivenNames.Text(clientDetails.GivenNames);
      C.txtLastName.Text(clientDetails.LastName);
      C.dateDateOfBirth.Value(clientDetails.DateOfBirth);

      // Show
      C.tbIndividualClient.show();
    }
  }
  else {
    // No Client Loaded
    if (mSearchType.Code == "DebtorPerson" || mSearchType.Code == "DebtorPersonDateRange") {
      C.tbIndividualClient.show();
    }
    else {
      C.tbOrganisationClient.show();
    }
  }

  // Date Range sections
  if (mSearchType.Code == "DebtorOrganisationDateRange" || mSearchType.Code == "DebtorPersonDateRange") {
    C.tbDebtorOtherOptions.hide();
    C.tbDebtorDateRange.show();
  }
  else {
    C.tbDebtorOtherOptions.show();
    C.tbDebtorDateRange.hide();
  }
}

// ==================
// pageSearchCriteria
// ==================
function pageSearchCriteria_Refresh() {
  wbSearchCriteria_Preview();
}

// =================
// pageSearchResults
// =================
function pageSearchResults_Refresh() {
  // Hide content
  frmMain.Visible(false);

  // Run search
  PerformSearch();
}

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

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

// =================
// Finish Parameters
// =================
function CreateFinishParameters() {
  var params = {
    searchType: mSearchType.Description,
    billingReference: C.txtBillingReference.Text(),
    acceptDeclaration: C.chkDeclaration.Value(),
  }

  // Search By
  switch (mSearchType.Code) {
    case "Aircraft":
    case "IntellectualProperty":
    case "MotorVehicle":
    case "Watercraft":
      params.SerialNumber = C.txtSerialNumber.Text();
      params.SerialNumberType = C.cboSerialNumberType.Text();
      break;

    case "DebtorOrganisation":
    case "DebtorOrganisationDateRange":
      params.OrganisationType = C.cboOrganisationType.Text();
      params.CompanyNumber = C.txtOrganisationNumber.Text();
      params.OrganisationName = C.txtOrganisationName.Text();
      break;

    case "DebtorPerson":
    case "DebtorPersonDateRange":
      params.FirstName = C.txtGivenNames.Text();
      params.LastName = C.txtLastName.Text();
      params.DateOfBirth = C.dateDateOfBirth.Value();
      break;

    case "FinanceStatement":
      params.FinancingStatementId = C.txtFinancingStatement.Text();
      params.FinancingStatementIncludeHistory = C.chkFinancingStatementIncludeHistory.Value();
      break;

    case "PreviousSearch":
      params.ServiceLogPk = mPreviousSearchServiceLogPk;
      break;

    default:
      window.alert("Unhandled SearchType '" + mSearchType.Description + "'.");
      break;
  }

  // Shared Debtor / Person
  switch (mSearchType.Code) {
    case "DebtorOrganisation":
    case "DebtorPerson":
      // Non Date Range
      params.SecurityRegisterSearchCollateralType = C.cboCollateralType.Text();
      params.GrantorPMSI = (C.rblPmsi.Value() == "PMSI");
      params.GrantorNonPMSI = (C.rblPmsi.Value() == "NONPMSI");
      params.GrantorPMSIBoth = (C.rblPmsi.Value() == "BOTH");
      params.GrantorNonTransitional = C.chkGrantorNonTransitional.Value();
      params.GrantorTransitionalNonMigrated = C.chkGrantorTransitionalNonMigrated.Value();
      params.GrantorTransitionalMigrated = C.chkGrantorTransitionalMigrated.Value();
      break;

    case "DebtorOrganisationDateRange":
    case "DebtorPersonDateRange":
      // Date Range
      params.DateGrantorFrom = C.dateDebtorFrom.Value();
      params.DateGrantorTo = C.dateDebtorTo.Value();
      break;
  }

  return params;
}

// ==========================
// Perform PPSR B2G AU Search
// ==========================
function PerformSearch() {
  // Block UI
  widget.UI.Block("Performing Search, please wait...");

  // Params
  var params = CreateFinishParameters();

  // Search
  widget.GetString("PerformSearch", params, PerformSearch_Done, function(errorMessage) {
    // Unblock
    widget.UI.Unblock();

    // Cancel
    tabWizard_Move(-1);

    // Show content
    frmMain.Visible(true);

    // Error
    widget.UI.MsgBoxAlert(errorMessage);
  });
}

function PerformSearch_Done(data) {
  // Parse
  mSearchResults = JSON.parse(data);

  // Configure Grid if there are results, otherwise skip to the search criteria page
  if (mSearchResults &amp;&amp; mSearchResults.Response &amp;&amp; mSearchResults.Response.length != 0) {
    gridSearchResults_Refresh();
  }
  else {
    // If viewing Previous Searches, open in an HTML viewer. Otherwise move to Search Criteria page.
    if (mShowNoResultsInModalWindow) {
      // Return to Previous Search Page
      tabWizard_Move(-1);

      // Show No Results HTML in modal window
      widget.UI.Forms.ShowHtml("PPSR B2G Search Previous Search", mSearchResults.NoResultsHtml);
    }
    else {
      tabWizard_Move(1);
    }
  }

  // Last Parameters
  if (!mRecord.RunFromServiceLog) {
    mLastFinishParametersJson = JSON.stringify(CreateFinishParameters());
  }

  // Unblock
  widget.UI.Unblock();

  // Show content
  frmMain.Visible(true);

  // Refresh Parent if actioning a Workflow Item
  if (mRecord.WorkflowId) {
    widget.RefreshParent();
  }

  // Warning
  if (mSearchResults.Warning) {
    widget.UI.MsgBoxAlert(mSearchResults.Warning);
  }
}

// ===================
// cboOrganisationType
// ===================
function cboOrganisationType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Update Fields
  switch (C.cboOrganisationType.Text()) {
    case "":
      C.txtOrganisationName.VisibleRow(false);
      C.txtOrganisationNumber.VisibleRow(false);
      break;

    case "Organisation Name":
      C.txtOrganisationName.VisibleRow(true);
      C.txtOrganisationNumber.VisibleRow(false);
      break;

    default:
      C.txtOrganisationName.VisibleRow(false);
      C.txtOrganisationNumber.VisibleRow(true);
      break;
  }
}

// ============
// cboSearchType
// ============
function cboSearchType_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Reset
  mPreviousSearchServiceLogPk = 0;
  mShowNoResultsInModalWindow = false;

  // Default Control Values
  C.rblPmsi.Value("BOTH");
  C.chkGrantorNonTransitional.Value(true);
  C.chkGrantorTransitionalNonMigrated.Value(true);
  C.chkGrantorTransitionalMigrated.Value(true);

  // Get Search Type
  mSearchType = mRecord.SearchTypes.GetItem(C.cboSearchType.Text());

  // Requires Declaration?
  if (mSearchType) {
    switch (mSearchType.Code) {
      case "DebtorPerson":
      case "DebtorPersonDateRange":
        mDeclarationVisible = true;
        break;

      default:
        mDeclarationVisible = false;
        break;
    }
  }

  // Show / Hide Declaration
  if (mDeclarationVisible) {
    C.tbDeclaration.show();
  }
  else {
    C.tbDeclaration.hide();
  }

  // Update Controls
  chkDeclaration_Change();
}

// ==============
// chkDeclaration
// ==============
function chkDeclaration_Change(sender, e) {
  var showAkas = false;

  // Initialise
  C.tbFinancingStatement.hide();
  C.tbClientAka.hide();
  C.gridClientAka.Visible(false);
  C.tbSerialNumberSearchType.hide();

  // Determine which controls to show
  if (mSearchType) {
    if (!mDeclarationVisible || (mDeclarationVisible &amp;&amp; C.chkDeclaration.Value())) {
      switch (mSearchType.Code) {
        case "DebtorPerson":
          showAkas = HasAkas(false);
          break;
        
        case "DebtorOrganisation":
          showAkas = HasAkas(true);
          break;

        case "FinanceStatement":
          C.tbFinancingStatement.show();          
          break;
      }

      // Configure Dropdowns
      ConfigureSerialNumberType();
    }
  }
  
  // Show Akas?
  if (showAkas) {
    // Refresh
    gridClientAka_Refresh();
  
    // Show
    C.tbClientAka.show();
    C.gridClientAka.Visible(true);
  }
  else {
    C.tbClientAka.hide();
    C.gridClientAka.Visible(false);
  }
}

// ======================================================================
// Determines if any Akas are present (either organisation or individual)
// ======================================================================
function HasAkas(isOrganisation) {
  if (mRecord_ClientAkas) {
    for (var i = 0; i &lt; mRecord_ClientAkas.length; i++) {
      var item = mRecord_ClientAkas[i];
      
      if (isOrganisation &amp;&amp; item.IsOrganisation) {
        return true;        
      }
      else if (!isOrganisation &amp;&amp; !item.IsOrganisation) {
        return true;
      }
    }
  }
  
  return false;
}

// ===============================
// Configures Serial Number fields
// ===============================
function ConfigureSerialNumberType() {
  // Reset
  C.tbSerialNumberSearchType.hide();
  C.cboSerialNumberType.Text("");
  C.txtSerialNumber.Text("");

  // Get item
  var item = mRecord_SerialNumberSearchTypes.GetItem(mSearchType.Code);
  if (item) {
    // Update
    C.cboSerialNumberType.ListFromCsvString(item.ListCsv);
    C.lblSerialNumberSearchType.TooltipText(item.Tooltip);

    // Show
    C.tbSerialNumberSearchType.show();
  }
}

// ===================
// cboSecurityStmtItem
// ===================
function cboSecurityStmtItem_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  // Reset
  C.cboSerialNumberType.Text("");
  C.txtSerialNumber.Text("");

  // Update Controls
  cboSerialNumberType_Change();
}

// ===================
// cboSerialNumberType
// ===================
function cboSerialNumberType_Change(sender, e) {
  var found = false;

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

  // Find item and update item defaults
  if (mRecord_SecurityItems) {
    for (var i = 0; i &lt; mRecord_SecurityItems.length; i++) {
      var item = mRecord_SecurityItems[i];

      if (item.Description == C.cboSecurityStmtItem.Text()) {
        // Update Controls
        if (item.SearchType != C.cboSearchType.Text()) {
          C.cboSearchType.Text(item.SearchType);
          cboSearchType_Change();
        }

        // Default fields
        switch (item.SearchType) {
          case "Aircraft":
          case "Intellectual Property":
          case "Motor Vehicle":
          case "Watercraft":
            // Set default type if initialising. Otherwise leave User input
            if (!e &amp;&amp; item.DefaultSerialNumberType) {
              C.cboSerialNumberType.Text(item.DefaultSerialNumberType);
            }

            // Set Value based upon Serial Number Type
            if (C.cboSerialNumberType.Text()) {
              for (var i = 0; i &lt; item.SecurityItemDefaults.length; i++) {
                var securityItem = item.SecurityItemDefaults[i];

                if (securityItem.SerialNumberType == C.cboSerialNumberType.Text()) {
                  found = true;
                  C.txtSerialNumber.Text(securityItem.Value);
                  break;
                }
              }

              // Clear if no value set
              if (!found) C.txtSerialNumber.Text("");
            }
            break;
        }
        break;
      }
    }
  }
}

// ===================
// GetPreviousSearches
// ===================
function GetPreviousSearches() {
  // Block UI
  widget.UI.Block("Performing Search, please wait...");

  // Params
  var params = {
    dateFrom: C.dateSearchFrom.Value(),
    dateTo: C.dateSearchTo.Value(),
    includeAllUsers: C.chkOptionsAllUsers.Value(),
    includeErrors: C.chkOptionsIncludeErrors.Value(),
    securityItemDescription: C.cboSecurityStmtItem.Text(),
  }

  // Search
  widget.GetString("GetPreviousSearches", params, GetPreviousSearches_Done, function(errorMessage) {
    // Unblock
    widget.UI.Unblock();

    // Error
    widget.UI.MsgBoxAlert(errorMessage);
  });
}

function GetPreviousSearches_Done(data) {
  mPreviousSearchResults = JSON.parse(data);

  // Refresh
  C.gridPreviousSearches.VirtualDataRefresh(mPreviousSearchResults);

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

// =============
// gridClientAka
// =============
function gridClientAka_Refresh() {
  // Add Columns
  C.gridClientAka.ClearColumns();
  C.gridClientAka.AddColumnString("Title", { caption: "Title", visible: !SearchTypeIsOrganisation() });
  C.gridClientAka.AddColumnString("GivenNames", { caption: "Given Names", visible: !SearchTypeIsOrganisation() });
  C.gridClientAka.AddColumnString("LastName", { caption: "Last Name", visible: !SearchTypeIsOrganisation() });
  C.gridClientAka.AddColumnString("Name", { caption: "Name", visible: SearchTypeIsOrganisation() });
  C.gridClientAka.AddColumnString("Notes", { caption: "Notes" });

  // Actions

  // Refresh
  C.gridClientAka.VirtualDataRefresh(mRecord_ClientAkas);

  // Select first row
  C.gridClientAka.ActivateFirstDataRow();
}

function gridClientAka_InitialiseRow(e) {
  var item = mRecord_ClientAkas[e.row.listIndex];

  // Update cells
  e.row.AutoBind(item);
}

function gridClientAka_RowDrilldown(e) {
  tabWizard_Move(1);
}

// ====================
// gridPreviousSearches
// ====================
function gridPreviousSearches_Refresh() {
  // Add Columns
  C.gridPreviousSearches.ClearColumns();
  C.gridPreviousSearches.AddColumnDrilldown();
  C.gridPreviousSearches.AddColumnDateTime("Date", { caption: "Date" });
  C.gridPreviousSearches.AddColumnString("UserId", { caption: "User" });
  C.gridPreviousSearches.AddColumnString("SearchId", { caption: "Search No" });
  C.gridPreviousSearches.AddColumnInteger("ResultCount", { caption: "Count" });
  C.gridPreviousSearches.AddColumnString("BillingReference", { caption: "Billing Ref" });
  C.gridPreviousSearches.AddColumnString("BillingNumber", { caption: "Billing No" });
  C.gridPreviousSearches.AddColumnString("SearchType", { caption: "Search Type" });
  C.gridPreviousSearches.AddColumnString("Request", { caption: "Request" });
  C.gridPreviousSearches.AddColumnString("Errors", { caption: "Errors" });

  // Actions

  // Refresh
  C.gridPreviousSearches.VirtualDataRefresh(mPreviousSearchResults);
}

function gridPreviousSearches_InitialiseRow(e) {
  var item = mPreviousSearchResults[e.row.listIndex];

  // Update cells
  e.row.AutoBind(item);

  // Errors
  e.row.cells.Errors.colour = "red";
}

function gridPreviousSearches_RowDrilldown(e) {
  // If there are no results, show in Modal window rather than moving to Search Criteria page
  mShowNoResultsInModalWindow = true;

  // Wizard Move
  tabWizard_Move(1);
}

// =================
// gridSearchResults
// =================
function gridSearchResults_Refresh() {
  // Show / Hide Columns
  var showWarnings = false;
  for (var i = 0; i &lt; mSearchResults.Response.length; i++) {
    var item = mSearchResults.Response[i];

    if (item.Warnings) showWarnings = true;
  }

  // Add Columns
  C.gridSearchResults.ClearColumns();
  C.gridSearchResults.AddColumnIcon("Icon", { caption: "" });
  C.gridSearchResults.AddColumnDrilldown();
  C.gridSearchResults.AddColumnString("FinancingStatementId", { caption: "Registration Number" });
  C.gridSearchResults.AddColumnDateTime("Date", { caption: "Date" });
  C.gridSearchResults.AddColumnString("CollateralType", { caption: "Collateral Type" });
  C.gridSearchResults.AddColumnString("CollateralClass", { caption: "Collateral Class" });
  C.gridSearchResults.AddColumnString("Description", { caption: "Description" });
  C.gridSearchResults.AddColumnString("Warnings", { caption: "Warnings", visible: showWarnings });

  // Actions
  var actions = [];
  if (mRecord.ShowRequestResponseXml) {
    actions.push({ actionId: "RequestXml", caption: "XML Request", tooltipText:"View XML Request", icon: "XML_Request" });
    actions.push({});
    actions.push({ actionId: "ResponseXml", caption: "XML Response", tooltipText:"View XML Response", icon: "XML_Response" });
  }
  C.gridSearchResults.Actions().Define(actions);

  // Give collection ability to form a unique cache key and preview parameters for the Widget
  mSearchResults.Response.GetCacheKey = function (index) {
    return mSearchResults.ServiceLogPk + "." + index;
  };
  mSearchResults.Response.GetPreviewFetchParameters = function (index) {
    var o = {
      index: index,
      serviceLogPk: mSearchResults.ServiceLogPk,
    };

    // Search Type specific
    if (mSearchType &amp;&amp; mSearchType.Code == "PreviousSearch") {
      var item = mPreviousSearchResults[C.gridPreviousSearches.ActiveDataRowListIndex()];

      o.SearchCriteria = item.SearchCriteria;
      o.SearchType = item.SearchType;
      o.Date = item.Date;
      o.UserPk = item.UserPk;
    }

    return o;
  };

  // Refresh
  C.gridSearchResults.VirtualDataRefresh(mSearchResults.Response);

  // Activate First Row
  C.gridSearchResults.ActivateFirstDataRow();
}

function gridSearchResults_Action(actionId) {
  switch (actionId.toUpperCase()) {
    case "REQUESTXML":
      ShowXml("Request");
      break;

    case "RESPONSEXML":
      ShowXml("Response");
      break;

    default:
      widget.UI.MsgBoxAlert("actionId: '" + actionId + "' is not supported.");
      break;
  }
}

function gridSearchResults_AfterRowActivate(e) {
  // Preview
  wbSearchResult_Preview();
}

function gridSearchResults_InitialiseRow(e) {
  var item = mSearchResults.Response[e.row.listIndex];

  // Update cells
  e.row.AutoBind(item);

  // Warnings
  e.row.cells.Warnings.colour = "red";
}

function gridSearchResults_RowDrilldown(e) {
  ShowFinancingStatement(e.row.listIndex);
}

// ===========================
// Show Request / Response XML
// ===========================
function ShowXml(type) {
  // Block UI
  widget.UI.Block("Getting XML. Please wait...");

  // Parameters
  var params = {
    serviceLogPk: mSearchResults.ServiceLogPk,
    type: type,
  }

  // Get XML
  widget.GetString("GetXml", params,
    // Success
    function(data) {
      // Unblock UI
      widget.UI.Unblock();

      // Show in Modal
      if (data) {
        widget.UI.Forms.ShowHtml(type + " XML", widget.UI.HtmlEncode(data));
      }
    },

    // Fail
    function(errorMessage) {
      // Unblock UI
      widget.UI.Unblock();

      // Error
      widget.UI.MsgBoxAlert(errorMessage);
    }
  );
}

// ====================================
// Selected Search Type is Organisation
// ====================================
function SearchTypeIsOrganisation() {
  if (mSearchType) {    
    switch (mSearchType.Code) {
      case "DebtorOrganisation":
      case "DebtorOrganisationDateRange":
        return true;
        break;
    }
  }
  
  return false;
}

// ========================
// Show Financing Statement
// ========================
function ShowFinancingStatement(index) {
  // Block UI
  widget.UI.Block("Getting Financing Statement. Please wait...");

  var params = {
    index: index,
    serviceLogPk: mSearchResults.ServiceLogPk,
  }

  // Get Financing Statement
  widget.GetString("GetSearchResultDetailed", params,
    // Success
    function(data) {
      // Unblock UI
      widget.UI.Unblock();

      // Show in Modal
      if (data) {
        widget.UI.Forms.ShowHtml("PPSR B2G Search", data);
      }
    },

    // Fail
    function(errorMessage) {
      // Unblock UI
      widget.UI.Unblock();

      // Error
      widget.UI.MsgBoxAlert(errorMessage);
    }
  );
}

// ==============
// wbSearchResult
// ==============
function wbSearchResult_Preview() {
  C.wbSearchResult.PreviewFromGridCollection(C.gridSearchResults, mSearchResults.Response, "GetSearchResultPreview");
}

// ================
// wbSearchCriteria
// ================
function wbSearchCriteria_Preview() {
  C.wbSearchCriteria.SetContent(mSearchResults.NoResultsHtml, false);
}

// ====================
// Notification Handler
// ====================
function Widget_NotificationHandler(actionId, data) {
  switch(actionId.toUpperCase()) {
    case "FORMCLOSE":
      // Closing Form
      if (mRecord &amp;&amp; mRecord.WorkflowId &amp;&amp; !mSearchResults) {
        widget.UI.MsgBoxConfirm("Closing this form without performing a Search will not action the Workflow Item.\n\nAre you sure you want to close this form?", {}, tabWizard_Cancel);
      }
      else {
        tabWizard_Cancel();
      }
      break;

    case "VIEWFINANCINGSTATEMENT":
      // View Financing Statement
      ShowFinancingStatement(C.gridSearchResults.ActiveDataRowIndex());
      break;

    default:
      break;
  }
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>120</TimeoutSeconds>
    <UniqueId>m-sQ2hHTnUK+xVLuKuAUHA</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption />
    <HtmlWidgetMaxHeight>0</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>1200</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceCssSummaryPage2>true</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <Icon>PPSR_AU_Search</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="ShowRequestResponseXml" type="Boolean">
            <BlankTip />
            <Caption>Show options to get Request and Response XML from the Search Results grid?</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>
          <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="AccountAppId" 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.AccountApps</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="AccountAppApplicantPk" 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>false</GroupDigits>
            <MaxValue />
            <MinValue />
            <NumberSpecialType>None</NumberSpecialType>
            <SpinChange>1</SpinChange>
          </Parameter>
          <Parameter name="AccountAppCollateralPk" 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>false</GroupDigits>
            <MaxValue />
            <MinValue />
            <NumberSpecialType>None</NumberSpecialType>
            <SpinChange>1</SpinChange>
          </Parameter>
          <Parameter name="ClientId" 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.Clients</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="SecurityStmtId" 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.SecurityStmts</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="SecurityStmtItemPk" 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>false</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="ServiceLogPk" 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>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>