Article Details
Id:21989
Product:finPOWER Connect
Type:NEW
Version:6.00.00
Opened:14/10/2024
Closed:13/01/2025
Released:17/04/2025
Job: J034476
High Importance
Breaking Change

Business Layer; finBL.Reports; now gives access to the entire finPOWER Connect Reporting engine

Previously, the finPOWER Connect reporting engine (ISfinReports), was not part of the main business layer and was passed separately into areas such as Report Templates and Documents that were configured to allow access to reports.

This object is now available directly from Scripts via finBL.Reports.

NOTE: Much of the functionality of finBL.Reports such as the ReportFunctions object requires references to ActiveReports (the reporting component used by finPOWER Connect). These are intentionally not added to Script which means Scripts are limited to using only a small subset of reporting functionality. This is by design.

How to use this object is outside the scope of this article but the example below, shows how a "General" type Script can create, configure and run a report:

Option Explicit On
Option Strict On

' Other
Private mDesktopMode As Boolean

Public Function Main(parameters As ISKeyValueList) As Boolean

  Dim FileExportPackageHandler As finwsFileExportPackageHandler
  Dim Report As I_ISReportBaseBL
  Dim ReportFileName As String
  Dim Success As Boolean
  
  ' Assume Success
  Success = True
  
  ' Initialise
  mDesktopMode = (finBL.WebConfigPk = 0)
  
  ' Create Report
  Success = finBL.Reports.CreateReportForScript(isefinReportType.AccountAppList, Report)
  
  ' Update Parameters
  If Success Then
    ' Calculate defaults
    Report.Parameters.CalculateValues(True, False)
    
    ' Update
    With Report.Parameters
    End With
    
    ' Recalculate Invisible Parameters
    ' NOTE: This mimics how the User Interface works when a User runs a Report
    Report.Parameters.CalculateValues(False, True)
  End If
    
  ' Run Report
  If Success Then
    ' NOTE: When running from finPOWER Connect Cloud, the Report_Progress is meaningless
    finBL.StatusProcessBegin("Running report")
    Main = Report.RunForScript(AddressOf Report_Progress)        
    finBL.StatusProcessEnd()
  End If
    
  ' Save Report to PDF
  ' NOTE: This code will work on both desktop and in finPOWER Connect Cloud and is hence more involved than simply just saving to a PDF file
  If Success Then
    ' Create Export Package
    Success = finBL.HtmlWidgetUtilities.CreateProcessFileExportPackageHandler(ScriptInfo.ScriptCaption, ScriptInfo.ScriptId, FileExportPackageHandler)
    
    ' Create a File Name for the Package
    If Success Then
      FileExportPackageHandler.CreateFileName(String.Format("Report_{0}.pdf", finBL.TimeZoneFunctions.GetCurrentDatabaseDateTime().ToString("yyyyMMdd_HHmmss")))
      ReportFileName = FileExportPackageHandler.GetFullFileName(0)
      
      ' Save the Report
      Success = finBL.Reports.ReportFunctions.ExportReportToPdfForScript(Report, ReportFileName, ReportFileName)
    End If
    
    ' Update Package Status
    If Success Then
      FileExportPackageHandler.StatusUpdateInProgress(0)
    End If
    
    ' Finalise
    If Success Then
      If FileExportPackageHandler.StatusUpdateComplete(mDesktopMode) Then
        ' Desktop finalise has removed the "Package_" prefix from the file names
        If mDesktopMode Then
          ReportFileName = FileExportPackageHandler.GetShortFileName(0)        
        End If
      Else
        Success = False
      End If
    ElseIf FileExportPackageHandler IsNot Nothing Then
      Success = FileExportPackageHandler.StatusUpdateFailed()
    End If
  End If
  
  ' Debug
  If Success Then
    finBL.DebugPrint(ReportFileName)
  End If
  
  Return Success

End Function

Public Sub Report_Progress(message As String, 
                           phasePercent As Double,
                           overallPercent As Double)

  If overallPercent >= 0 Then
    finBL.StatusProcess(overallPercent, message)
  Else
    ' A value of -1 may be passed (used internally within finPOWER Connect) so ignore
  End If
  
End Sub