<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2023-11-07T23:39:55.0000000">
    <CreatedUserId>ADMIN</CreatedUserId>
    <CreatedUtcDate>2023-11-02T22:14:41.1270000</CreatedUtcDate>
    <UpdatedUserId>ADMIN</UpdatedUserId>
    <UpdatedUtcDate>2023-11-07T23:39:33.2570000</UpdatedUtcDate>
    <ScriptId>PPSRNZPENDREQ</ScriptId>
    <Description>PPSR NZ Pending Request</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_PPSRNZPendingRequest
Option Explicit On
Option Strict On

' #################################################################
' PPSR NZ Pending Request wizard HTML Widget
'
' Version: 1.00 (08/11/2023)
'
' Usage: System-defined HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  08/11/2023  ISS      J032362   Created
' #################################################################

' Constants
Private Const FORM_KEY As String = "PPSRNZPendingRequest"

' Common Parameters
Private mSecurityStmtPk As Integer
Private mServiceLogPk 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

  ' 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
    mSecurityStmtPk = .GetInteger("SecurityStmtPk")
    mServiceLogPk = .GetInteger("ServiceLogPk")
  End With

  ' Validate
  Main = finBL.HtmlWidgetUtilities.HasPermissionToViewFormKey(FORM_KEY)
  
  ' Handle Events
  If Main Then
    Select Case eventId
      Case ""
        ' Main event, i.e., return initial HTML content (excluding html and body tags)
        returnValue = ScriptInfo.TemplateText
  
      Case "CheckPpsr"
        ' Check PPSR
        Main = CheckPpsr(returnValue)
        
      Case "Finish"
        ' Finish wizard
        Main = Finish()
  
      Case "GetInitialisationInfo"
        ' Get Initialisation Information required for this wizard
        Main = GetInitialisationInfo(returnValue)
  
      Case "WizardValidate"
        ' Validate wizard page
        Main = WizardValidate(parametersJson, returnValue)
  
      Case Else
        finBL.Error.ErrorBeginFormat("Unhandled event '{0}'.", eventId)
        Main = False
    End Select
  End If

End Function

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

  Dim ErrorMessage As String
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim ServiceLog As ISServiceLog
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate
  If mSecurityStmtPk = 0 Then
    Success = False
    finBL.Error.ErrorBegin("A valid Security Statement Pk must be specified.")
  ElseIf mServiceLogPk = 0 Then
    Success = False
    finBL.Error.ErrorBegin("A valid Service Log Pk must be specified.")
  End If

  ' Load Service Log
  If Success Then
    Success = GetServiceLog(ServiceLog)
  End If

  ' Further validation
  If Success Then
    If Not finBL.SecurityRegistry.Service_PPSRNZ.CanUpdatePendingServiceLog(ServiceLog, ErrorMessage) Then
      Success = False
      finBL.Error.ErrorBegin(ErrorMessage)
    End If
  End If
  
  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Record
      .CreatedDate = finBL.HtmlWidgetUtilities.GetJsonUtcDateTimeFromDatabaseDateTime(ServiceLog.CreatedDate)
      .UserId = finBL.Users.ItemByPkSafe(ServiceLog.CreatedUserPk).UserIdResolved
      .ProductId = ServiceLog.ProductId
      .RequestId = ServiceLog.RequestReference

      ' Configuration
      .AppTitle = finBL.AppTitle
      .PromptOnCommit = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnCommit
    End With
  End If

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

  Return Success

End Function

''' &lt;summary&gt;
'''  Check PPSR for updates.
''' &lt;/summary&gt;
Private Function CheckPpsr(ByRef returnValue As String) As Boolean
  
  Dim Data As Object
  Dim Request_GetTransactions As ISSecurityRegistryRequest_PPSRNZ_GetTransactions
  Dim Response_GetTransactions As ISSecurityRegistryResponse_PPSRNZ_GetTransactions  
  Dim ServiceLog As ISServiceLog
  Dim ServiceLogCreateDetails As ISServiceLogCreateDetails
  Dim Success As Boolean
  Dim SummaryHtml As String
  
  ' Assume Success
  Success = True
  
  ' Get Service Log
  Success = GetServiceLog(ServiceLog)
  
  ' Create Request
  If Success Then
    Request_GetTransactions = finBL.SecurityRegistry.Service_PPSRNZ.CreateRequest_GetTransactions()
    Request_GetTransactions.RequestId = ServiceLog.RequestReference
  End If
  
  ' Get Transactions
  If Success Then
    Success = finBL.SecurityRegistry.Service_PPSRNZ.ExecuteGetTransactions(Request_GetTransactions, Response_GetTransactions, ServiceLogCreateDetails)
  End If
  
  ' If there are no items, get the Summary page now
  If Success Then
    If Response_GetTransactions.Transactions.Count &lt; 2 Then
      SummaryHtml = finBL.SecurityRegistry.Service_PPSRNZ.GetPendingTransactionSummary(Response_GetTransactions, ServiceLog, 0, Nothing)
    Else 
      Success = False
      finBL.Error.ErrorBegin("The PPSR NZ Pending Request update wizard only supports updating requests with one or zero Transactions.")
    End If
  End If
  
  ' Return
  If Success Then
    Data = New With {
      .GetTransactionServiceLogPk = ServiceLogCreateDetails.ServiceLogPk,
      .SummaryHtml = SummaryHtml
    }
  End If
  
  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(Data, returnValue)
  End If
  
  Return Success
  
End Function

''' &lt;summary&gt;
'''  Get the Service Log.
''' &lt;/summary&gt;
Private Function GetServiceLog(ByRef serviceLog As ISServiceLog) As Boolean
  
  Dim Success As Boolean
  
  ' Assume Success
  Success = True
  
  ' Initialise ByRef Parameters
  serviceLog = Nothing
  
  ' Load Service Log
  Success = finBL.Database.GetServiceLog(mServiceLogPk, serviceLog)
  
  Return Success
  
End Function

''' &lt;summary&gt;
'''  Finish, i.e., Commit changes.
''' &lt;/summary&gt;
''' &lt;param name="parametersJson"&gt;
'''  A JSON formatted WizardFinishParameters object.
''' &lt;/param&gt;
Private Function Finish() As Boolean

  Dim Response As ISSecurityRegistryResponse
  Dim Response_GetTransactions As ISSecurityRegistryResponse_PPSRNZ_GetTransactions
  Dim Response_Transaction As ISSecurityRegistryResponse_PPSRNZ_Transaction
  Dim ServiceLog As ISServiceLog
  Dim Success As Boolean
  Dim GetTransactionServiceLogPk As Integer

  ' Assume Success
  Success = True
  
  ' Parameters
  With mCombinedParameters
    GetTransactionServiceLogPk = .GetInteger("GetTransactionServiceLogPk")
  End With
  
  ' Get Transaction Service Log
  Success = finBL.Database.GetServiceLog(GetTransactionServiceLogPk, ServiceLog)
  
  ' Get Service Log Response
  If Success Then
    If finBL.SecurityRegistry.GetSecurityRegistryResponseFromServiceLog(ServiceLog, Response) Then
      If TypeOf Response Is ISSecurityRegistryResponse_PPSRNZ_GetTransactions Then
        Response_GetTransactions = DirectCast(Response, ISSecurityRegistryResponse_PPSRNZ_GetTransactions)
      Else 
        Success = False
        finBL.Error.ErrorBegin("Invalid Response Type.")
      End If        
    Else 
      Success = False
    End If
  End If  
  
  ' Get Transaction
  If Success Then
    If Response_GetTransactions.Transactions.Count &lt;&gt; 0 Then
      Response_Transaction = Response_GetTransactions.Transactions(0)
    End If
  End If
  
  ' Update
  If Success Then
    Success = finBL.SecurityRegistry.Service_PPSRNZ.UpdatePendingServiceLog(mSecurityStmtPk, mServiceLogPk, GetTransactionServiceLogPk, Response_Transaction)
  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 Data As Object
  Dim FailedControlId As String
  Dim FailedMessage As String
  Dim PageId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

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

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

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

  Return Success

End Function



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

  ' Record
  Public CreatedDate As Date
  Public UserId As String
  Public ProductId As String
  Public RequestId As String

  ' Configuration
  Public AppTitle As String
  Public PromptOnCommit As Boolean

End Class



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

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

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

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

  End Sub

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

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

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;div class="header"&gt;&lt;/div&gt;
    &lt;div class="summary"&gt;&lt;/div&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabWizard" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="General" tooltipText="Review details about this Pending Request."&gt;Pending Request Information&lt;/li&gt;
      &lt;ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;

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

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblRequestDetails"&gt;Request details&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;   
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="dateRequestDate"&gt;Date/Time:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="dateRequestDate" /&gt;&lt;/td&gt;
        &lt;/tr&gt;     
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtRequestUserId"&gt;User Id:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRequestUserId" /&gt;&lt;/td&gt;
        &lt;/tr&gt; 
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtRequestProductId"&gt;Product Id:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRequestProductId" /&gt;&lt;/td&gt;
        &lt;/tr&gt; 
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtRequestId"&gt;Request Id:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRequestId" /&gt;&lt;/td&gt;
        &lt;/tr&gt; 
        
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCheckPpsr"&gt;Check the PPSR to see if this request succeeded&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;   
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;button id="cmdCheckPpsr" class="is-button ok"&gt;Check PPSR&lt;/button&gt;&lt;/th&gt;
        &lt;/tr&gt;   
        
        &lt;tr style="height:100%"&gt;
          &lt;th colspan="2" style="height:100%; padding-top:8px"&gt;&lt;div id="wbSummary" class="is-dock-fill"&gt;&lt;/div&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;

  &lt;/div&gt;

  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdCancel" class="is-button"&gt;Cancel&lt;/button&gt;
    &lt;button id="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;

// Other
var mPpsrData;

// Controls
var C = {
  // General
  tableGeneral: null,
  lblRequestDetails: null,
  dateRequestDate: null,
  txtRequestUserId: null,
  txtRequestProductId: null,
  txtRequestId: null,
  
  lblCheckPpsr: null,
  
  wbSummary: null,
}

// Form
var frmMain;
var tabWizard;

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

var cmdCheckPpsr;

// ==========
// Initialise
// ==========
$(function () {
  // --------
  // Controls
  // --------
  //   General
  C.tableGeneral = $("#tableGeneral");
  C.lblRequestDetails = widget.UI.Label("lblRequestDetails", {});
  C.dateRequestDate = widget.UI.DateBox("dateRequestDate", {
    allowTime: true,
    readOnly: true,
  });
  C.txtRequestUserId = widget.UI.TextBox("txtRequestUserId", {
    readOnly: true,
    maxLength: 50,
  });
  C.txtRequestProductId = widget.UI.TextBox("txtRequestProductId", {
    readOnly: true,
    maxLength: 50,
  });
  C.txtRequestId = widget.UI.TextBox("txtRequestId", {
    readOnly: true,
    maxLength: 100,
  });
  
  C.lblCheckPpsr = widget.UI.Label("lblCheckPpsr", {});
  
  C.wbSummary = widget.UI.PreviewPane("wbSummary", {});

  // Grids

  // Create Widget form
  // NOTE: Hide by default for a cleaner startup
  frmMain = new widget.UI.Form("frmMain", { captionWidth: "9em", textboxWidth: "20em", 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"); });

  cmdCheckPpsr = $("#cmdCheckPpsr");
  cmdCheckPpsr.click(function() { Form_ExecuteAction("CheckPpsr"); });

  // Reset
  Form_Reset();
});

// ==========
// Reset Form
// ==========
function Form_Reset() {
  // Defaults
  C.wbSummary.VisibleRow(false);

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

  // Resize
  Form_Resize();

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

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

  // Hide content
  frmMain.Visible(false);

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

  // Load Initialisation details
  widget.GetString("GetInitialisationInfo", {},
    // Success
    function (data) {
      mRecord = JSON.parse(data);
      Fields_Load();
    },

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

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.dateRequestDate.Value(mRecord.CreatedDate);
    C.txtRequestUserId.Text(mRecord.UserId);
    C.txtRequestProductId.Text(mRecord.ProductId);
    C.txtRequestId.Text(mRecord.RequestId);
  }

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

  // Update Controls

  // Update fields
  Fields_Update();

  // Refresh Tab
  tabWizard_Refresh();
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // Not used by this wizard since there is no concept of updating an object behind the wizard
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Information Lists

  // Lists

  // Controls
  if (mRecord) {
  }

  // Update Buttons
  tabWizard_UpdateButtons();

  // 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() {
  // Back and Next Buttons?
  if (tabWizard.TabCount() == 1) {
    cmdBack.hide();
    cmdNext.hide();
  }
  else {
    var tabIndex = tabWizard.SelectedTabIndex();
    cmdBack.prop("disabled", tabIndex &lt;= 0);
    cmdNext.prop("disabled", tabIndex &gt;= tabWizard.TabCount() - 1);
  }

  // Cancel/ Finish Button
  if (tabWizard.TabCount() != 1) cmdFinish.prop("disabled", !cmdNext.prop("disabled"));
  
  // Custom
  if (mPpsrData) {
    cmdFinish.prop("disabled", false);
  }
  else {
    cmdFinish.prop("disabled", true);
  }
}

// ==========
// Resize Tab
// ==========
function tabWizard_Resize() {
  switch (tabWizard.SelectedTabId()) {
    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)) {
        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)) {
      default:
        break;
    }
  }

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

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

  // Tweak fields

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

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

  // Resize Wizard
  tabWizard_Resize();

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

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

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

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

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

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

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

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

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

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

  if (o.FailedMessage) {
    // -----------------
    // Validation failed
    // -----------------
    var o = JSON.parse(data);
    widget.UI.MsgBoxAlert(o.FailedMessage);
    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();
}

// =================
// Execute an Action
// =================
function Form_ExecuteAction(actionId) {
  switch (actionId.toUpperCase()) {
    case "CHECKPPSR":
      // Check PPSR for updates
      Form_ExecuteAction_CheckPpsr();
      break;
      
    case "FINISH":
      // Finish
      Form_ExecuteAction_Finish();
      break;

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

// =================
// Check PPSR Action
// =================
function Form_ExecuteAction_CheckPpsr() {
  mPpsrData = null;

  // Block UI
  widget.UI.Block("Checking PPSR for updates, please wait...");
  
  // Get data
  widget.GetString("CheckPpsr", {}, Form_ExecuteAction_CheckPpsr_Done, function(errorMessage) {
    // Unblock UI
    widget.UI.Unblock();
    
    // Error
    widget.UI.MsgBoxAlert(errorMessage);
    
    // Update Buttons
    tabWizard_UpdateButtons();
  });
}

function Form_ExecuteAction_CheckPpsr_Done(data) {
  // Parse
  if (data) mPpsrData = JSON.parse(data);
  
  // Show Summary or Transactions grid
  if (mPpsrData) {
    // Update Preview Pane
    C.wbSummary.SetContent(mPpsrData.SummaryHtml, false);
    
    // Show
    C.tableGeneral.css("height", "100%");
    C.wbSummary.VisibleRow(true);
  }
  
  // Update Buttons
  tabWizard_UpdateButtons();
  
  // Unblock UI
  widget.UI.Unblock();
}

// =============
// Finish Action
// =============
function Form_ExecuteAction_Finish() {
  // Validate
  tabWizard_Validate(function () {
    if (mRecord.PromptOnCommit) {
      // Confirm
      var heading = "Update PPSR Transaction";
      var message = "Update PPSR Transaction in " + mRecord.AppTitle + "?";
      widget.UI.MsgBoxConfirm(message, { heading: heading }, function () { Form_ExecuteAction_FinishPost(); }, null);
    }
    else {
      // Commit without prompting
      Form_ExecuteAction_FinishPost();
    }
  });
}

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

  // Create Parameters
  var params = CreateFinishParameters();

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

      // Refresh Parent (to show updated details)
      widget.RefreshParent();
    },

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

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

function CreateFinishParameters() {
  // Create Parameters
  if (mPpsrData) {
    var params = {      
      getTransactionServiceLogPk: mPpsrData.GetTransactionServiceLogPk
    };
  }  

  return params;
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <TimeoutSeconds>60</TimeoutSeconds>
    <UniqueId>kghEHMMEk0CQz4KZjn9Wwg</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption />
    <HtmlWidgetAllowInitialEventCaching>false</HtmlWidgetAllowInitialEventCaching>
    <HtmlWidgetMaxHeight>900</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceChartsApex>false</HtmlWidgetResourceChartsApex>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <Icon />
    <RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled>
    <RunAsAdministrator>false</RunAsAdministrator>
    <WebServiceName />
    <WebServiceAllowAnonymous>false</WebServiceAllowAnonymous>
    <WebServiceSendDebugInformation>false</WebServiceSendDebugInformation>
    <ShowInMenu>None</ShowInMenu>
    <ParametersType>Custom</ParametersType>
    <Parameters>
      <ISParameterDefs version="1.00">
        <Parameters>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Form options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" 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="SecurityStmtPk" 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>