Stonefield Query calls the ReportEngine.SetupCrystalReport script when the users runs a Crystal report. This allows you to change the report's properties before it runs.

Parameters
A reference to the Stonefield Query Application object and a reference to the Crystal report object.

Return Value
True if the report can run, False if not.

Example
This example sets the value of the tsDataFolder variable in the Crystal report to the name of the current database.

Visual FoxPro

lparameters toApplication as SQApplication, toReport
local loFormulas, loFormula, loDatabase, loDatasource
loFormulas = toReport.FormulaFields
loFormula = loFormulas.GetItemByName('tsDataFolder')
loDatabase = toApplication.DataEngine.Databases.GetMainDatabase()
loDataSource = loDatabase.CurrentDataSource
loFormula.Text = '"' + loDatasource.Database + '"'
return .T.

VBScript

function Main(Application, Report)
dim Formulas, Formula, Database, Datasource
set Formulas = Report.FormulaFields
set Formula = Formulas.GetItemByName("tsDataFolder")
set Database = Application.DataEngine.Databases.GetMainDatabase()
set DataSource = Database.CurrentDataSource
Formula.Text = Chr(34) + Datasource.Database + Chr(34)
Main = True
end function

JavaScript

function Main(Application, Report) {
var Formulas, Formula, Database, Datasource ;
Formulas = Report.FormulaFields ;
Formula = Formulas.GetItemByName("tsDataFolder") ;
Database = Application.DataEngine.Databases.GetMainDatabase() ;
DataSource = Database.CurrentDataSource ;
Formula.Text = '"' + Datasource.Database + '"' ;
return true ;
}

C#

Please note that the method in this script must be named ReportEngine_SetupCrystalReport.

public static object ReportEngine_SetupCrystalReport(SFQApplication sfqApplication, 
  object report)
{	
  object Formulas = ReflectionService.GetProperty(report, "FormulaFields");
  object Formula = ReflectionService.CallMethod(Formulas, "GetItemByName", 
    new object[] { "tsDataFolder" });
    
  Database database = sfqApplication.DataEngine.Databases.GetMainDatabase() ;
  DataSource dataSource = database.CurrentDataSource ;
    
  ReflectionService.SetProperty(Formula, "Text", '"' + dataSource.Database + '"');

  return true ;
}

VB.NET

Please note that the method in this script must be named ReportEngine_SetupCrystalReport.

public shared function
  ReportEngine_SetupCrystalReport(sfqApplication as SFQApplication,
  report as object) as Boolean
  
  Dim Formulas As Object = ReflectionService.GetProperty(report, "FormulaFields")
  Dim Formula As Object = ReflectionService.CallMethod(Formulas, "GetItemByName",
    "tsDataFolder")

  Dim database As Database = sfqApplication.DataEngine.Databases.GetMainDatabase()
  Dim dataSource As DataSource = database.CurrentDataSource

  ReflectionService.SetProperty(Formula, "Text", "" + dataSource.Database + "")

  Return True
End Function

See also

Scripts

© Stonefield Software Inc., 2024 • Updated: 06/06/16
Comment or report problem with topic