The DataEngine.GetCustomMetaData script is intended to be used to customize the data dictionary at runtime. Why not just do this in Stonefield Query Studio? There may be many reasons:

  • Perhaps you don't want certain users to access certain tables. In that case, you want to set the Reportable property of the appropriate Table objects to False based on the user name. While you could use role-based security for this, doing it in the DataEngine.GetCustomMetaData script makes it more dynamic.

  • If you allow your users to customize the caption for certain fields, or even add their own custom fields to the tables, you want Stonefield Query to know about the changes the user made.

  • If users can purchase your application by module, you don't want those tables belonging to modules the user hasn't purchased listed in Stonefield Query.

This script is called immediately after Stonefield Query loads the data dictionary from the REPMETA table into its DataEngine collections. So, you have full access to the in-memory data dictionary without altering the disk copy in REPMETA.

If you want to display an error message and terminate Stonefield Query (for example, if your script determines that something is wrong), set SQApplication.DataEngine.ErrorMessage to the desired message and return .F. from your script code.

Parameters
A reference to the Stonefield Query Application object.

Return Value
True if Stonefield Query can continue, False to terminate.

Example

Visual FoxPro
Here's an example that adds custom fields the user has added to their tables to the Stonefield Query data dictionary. It assumes there's a table called CUSTFLDS located in the directory specified in the Application object's TargetApplicationDirectory property that contains the necessary information. In this table, FIELDNAME contains the field name, FIELDTYPE contains the field type, FIELDLEN contains the field width, FIELDDEC contain the number of decimals, and FIELDHEAD contains the caption for the field.

lparameters toApplication as SQApplication
local lnSelect, loField as Field, lcName
lnSelect = select()
select 0
use (toApplication.TargetApplicationDirectory + 'CUSTFLDS')
scan
  lcName  = trim(FIELDNAME)
  loField = toApplication.DataEngine.Fields.AddItem(lcName)
  loField.Type     = FIELDTYPE
  loField.Length   = FIELDLEN
  loField.Decimals = FIELDDEC
  loField.Caption  = trim(FIELDHEAD)
endscan
use
select (lnSelect)
return .T.

VBScript
This example makes the EMPLOYEES and PAYROLL tables invisible to all but the ADMIN user.

function Main(Application)
dim Table
if Application.Users.UserName <> "ADMIN" then
  set Table = Application.DataEngine.Tables.Item("EMPLOYEES")
  Table.Reportable = False
  set Table = Application.DataEngine.Tables.Item("PAYROLL")
  Table.Reportable = False
end if
Main = True
end function

JavaScript
This example makes the EMPLOYEES and PAYROLL tables invisible to all but the ADMIN user.

function Main(Application) {
var Table ;
if (Application.Users.UserName != 'ADMIN') {
  Table = Application.DataEngine.Tables.Item('EMPLOYEES') ;
  Table.Reportable = false ;
  Table = Application.DataEngine.Tables.Item('PAYROLL') ;
  Table.Reportable = false ;
}
return true ;
}

C#

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

public static bool DataEngine_GetCustomMetaData(SFQApplication sfqApplication)
{	
  if(sfqApplication.Users.UserName != "ADMIN")
  {
    // Please note that any changes you make to this item will only be saved in
    // Stonefield Query after you call the Dispose() method or by using the 'using'
    // syntax below which calls Dispose() for you automatically
    using(Table table = sfqApplication.DataEngine.Tables.Item("CATEGORIES"))
    {
      table.Reportable = false;
    }

    using(Table table = sfqApplication.DataEngine.Tables.Item("SHIPPERS"))
    {
        table.Reportable = false;
    }
  }
  return true;
}

VB.NET

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

public shared function DataEngine_GetCustomMetaData(sfqApplication as SFQApplication) as Boolean
  if sfqApplication.Users.UserName <> "ADMIN" Then

    ' Please note that any changes you make to this item will only be saved in
    ' Stonefield Query after you call the Dispose() method or by using the 'using'
    ' syntax below which calls Dispose() for you automatically
    using table As Table = sfqApplication.DataEngine.Tables.Item("CATEGORIES")
      table.Reportable = false
    End Using

    using table As Table = sfqApplication.DataEngine.Tables.Item("SHIPPERS")
      table.Reportable = false
    End Using
  End If
  Return true
End Function

See also

DataEngine Object | Scripts

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