Stonefield Query calls the Application.AfterSetup script after all setup tasks are done but before reports are loaded in the Reports Explorer. There are a variety of uses for this script, including storing information in the Application object for retrieval later (the examples in this topic show this usage).

The Application.AfterSetup script is not called if a report is run from the Windows command line or another application and you specify the EXIT option. That's because the report is run before that script executes and then Stonefield Query terminates because of the EXIT option. If you need setup tasks performed even under these conditions, use Application.BeforeSetup instead.

Parameters
A reference to the Stonefield Query Application object.

Return Value
True if the application should continue, False if it should terminate.

Example
This example retrieves a tax rate from a single-record "constants" table using the ExecuteSQLStatement method and stores it in a new property of the Application object so it can be used in other scripts, such as those called from calculated fields. Those scripts simply refer to SQApplication.TaxRate to retrieve that value. The benefit of doing this in Application.AfterSetup is that it only executes once; doing this in a calculated field script causes the constants table to be accessed to retrieve the same value many times.

Visual FoxPro

lparameters toApplication as SQApplication
local loDatabase as Database, lcSelect, llReturn
loDatabase = toApplication.DataEngine.Databases.GetMainDatabase()
lcSelect = 'select TAXRATE from CONSTANTS'
llReturn = not empty(loDatabase.ExecuteSQLStatement(lcSelect, ;
  '', 'CONSTANTS'))
if llReturn
  toApplication.AddProperty('TaxRate', CONSTANTS.TAXRATE)
  use in CONSTANTS
endif
return llReturn

VBScript

function Main(Application)
dim Database, XMLDOM
set Database = Application.DataEngine.Databases.GetMainDatabase()
SelectStmt = "select TAXRATE from CONSTANTS"
Results = Database.ExecuteSQLStatement(SelectStmt)
set XMLDOM = createobject("MSXML.DOMDocument")
XMLDOM.ASync = False
XMLDOM.LoadXML(Results)
TaxRate = XMLDOM.selectSingleNode("/DataSet/_resultset/taxrate").Text
Application.AddProperty("TaxRate", TaxRate)
Main = True
end function

JavaScript

function Main(Application) {
var Database, SelectStmt, Results, XMLDOM, TaxRate ;
Database = Application.DataEngine.Databases.GetMainDatabase() ;
SelectStmt = 'select TAXRATE from CONSTANTS' ;
Results = Database.ExecuteSQLStatement(SelectStmt) ;
XMLDOM = new ActiveXObject('MSXML.DOMDocument') ;
XMLDOM.ASync = false ;
XMLDOM.LoadXML(Results) ;
TaxRate = XMLDOM.selectSingleNode('/DataSet/_resultset/taxrate').Text ;
Application.AddProperty('TaxRate', TaxRate) ;
return true ;
}

C#

The method in this script must be named Application_AfterSetup.

public static bool Application_AfterSetup(SFQApplication sfqApplication)
{	
  bool result = false;

  Database database = sfqApplication.DataEngine.Databases.GetMainDatabase();
  string selectStmt = "select TAXRATE from CONSTANTS";

  string resultSet = database.ExecuteSQLStatement(selectStmt);

  XmlDocument doc = new XmlDocument();

  doc.LoadXml(resultSet);

  XmlNode node = doc.SelectSingleNode("/DataSet/_resultset/@taxrate");

  if (node != null)
    {
      string taxRate = node.Value;
      sfqApplication.AddProperty("TaxRate", taxRate);

      result = true;
    }

  return result;
}

VB.NET

The method in this script must be named Application_AfterSetup.

public shared function Application_AfterSetup(sfqApplication as SFQApplication) as Boolean

  Dim result As Boolean = False

  Dim database As Database = sfqApplication.DataEngine.Databases.GetMainDatabase()
  Dim selectStmt As String = "select TAXRATE from CONSTANTS"

  Dim resultSet As String = database.ExecuteSQLStatement(selectStmt)

  Dim doc As XmlDocument = New XmlDocument()

  doc.LoadXml(resultSet)

  Dim node As XmlNode = doc.SelectSingleNode("/DataSet/_resultset/@taxrate")

  If (Not node Is Nothing) Then
    Dim taxRate As String = node.Value
    sfqApplication.AddProperty("TaxRate", taxRate)

    result = True
  End If

  Return result
End Function

See also

Application.BeforeSetup | Application.Shutdown | Scripts

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