Tables & Schema
Table existence, field structure, unique keys, grids and links.
31 functions. All require apis/main_webservices.php to be included.
On this page: BackUpdateInfo ยท CountGridRows ยท FullTableList ยท GetLinkedTableDisplayField ยท GetLinkedTableLinkedField ยท GetLinkedTableName ยท GetTableGrids ยท TableExists ยท colCap ยท generateAutoSerial4UniqueField ยท getCompoundUnique ยท getFieldStru ยท getFieldsHavingAverage ยท getFieldsHavingCount ยท getFieldsHavingTotals ยท getFormTable ยท getGridAfter ยท getGridTableNames ยท getKeyField ยท getOptionalField ยท getPrintFile ยท getUniqueCharFields ยท getUniqueFieldNames ยท getUniqueFields ยท gridRow ยท isDateField ยท isFieldImage ยท isUniqueKey ยท stru ยท tableHasField ยท tabletitle
BackUpdateInfo()
Prototype
BackUpdateInfo( $cTable )
Description
- Returns the back-update configuration for a table โ how saving it writes values back into a linked table.
- Exposes link table, link/match fields, the event, the action and current-table field mapping.
Parameters
- <$cTable> : Base Table Name
Returns
- Array โ
['lnk_table','lnk_tbl_fld','lnk_tbl_match','event','action','cur_table','cur_tbl_fld'].
Return example
$bu = BackUpdateInfo('trn_production');
// ['lnk_table'=>'trn_salesorderg', 'action'=>'SET', ...]
:material-file-code: Source: apis/core.php
CountGridRows()
Prototype
CountGridRows( $cTable, $nID )
Description
- Counts the rows present in a grid (child) table for a given parent id.
- Use to validate that a document has at least one line item.
Parameters
$cTableโ Table Name$nIDโ id of entry
Returns
- Integer โ number of grid rows for that parent record.
Return example
$n = CountGridRows('trn_salesorderg', 1024);
// e.g. 7
Usage example
CountGridRows( 'trn_sales', 120 );
:material-file-code: Source: apis/core2.php
FullTableList()
Prototype
FullTableList()
Description
- Returns a list of all tables defined in the current project.
- Broader than
GetProjectTables()(which is limited to mst/trn).
Parameters
- none
Returns
- Array โ all project table names.
Return example
$all = FullTableList();
// ['mst_item','trn_salesorder','sys_keys', ...]
:material-file-code: Source: apis/core.php
GetLinkedTableDisplayField()
Prototype
GetLinkedTableDisplayField( $cTable, $cField )
Description
- Returns the field shown to the user from a linked table in a LINK definition.
- The human-readable column displayed instead of the raw id.
Parameters
- <$cTable> : Base Table Name
- <$cField> : Field name
Returns
- String โ the display field name on the destination table.
Return example
$df = GetLinkedTableDisplayField('trn_salesorder', 'customer');
// e.g. 'account'
:material-file-code: Source: apis/core.php
GetLinkedTableLinkedField()
Prototype
GetLinkedTableLinkedField( $cTable, $cField )
Description
- Returns the destination field used for matching in a field's LINK definition.
- This is the column on the linked table that the value joins to.
Parameters
- <$cTable> : Base Table Name
- <$cField> : Field name
Returns
- String โ the linked field name on the destination table.
Return example
$lf = GetLinkedTableLinkedField('trn_salesorder', 'customer');
// e.g. 'id'
:material-file-code: Source: apis/core.php
GetLinkedTableName()
Prototype
GetLinkedTableName( $cTable, $cField )
Description
- Extracts the linked table name encoded in a field's LINK_BROW / LINK_DDL definition.
- Use to follow a foreign-key style link defined in the field structure.
Parameters
- <$cTable> : Base Table Name
- <$cField> : Field name
Returns
- String โ the linked (destination) table name, or blank if not a link.
Return example
$lt = GetLinkedTableName('trn_salesorder', 'customer');
// e.g. 'fasmast'
:material-file-code: Source: apis/core.php
GetTableGrids()
Prototype
GetTableGrids( $cTable )
Description
- Returns full grid metadata for all grid tables attached to a table.
- Richer than
getGridTableNames()โ includes the grid configuration, not just names.
Parameters
- <$cTable>: Name of table
Returns
- Array โ grid info for each associated grid table.
Return example
$info = GetTableGrids('trn_salesorder');
// [ ['table'=>'trn_salesorderg', 'after'=>..., ...] ]
Usage example
$cGridTbls = GetTableGrids( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
TableExists()
Prototype
TableExists( $cTable )
Description
- Checks whether a table physically exists in the project's MySQL database.
- Pass the complete table name โ preferably built with
tbl()or via a#token#expansion.
Parameters
- <$cTable> : string FULL Tablename to be checked
Returns
- Boolean โ
trueif the table exists, elsefalse.
Return example
if (TableExists(tbl('trn_loomprogramg'))) {
// safe to query it
}
// returns: true | false
:material-file-code: Source: apis/core.php
colCap()
Prototype
ColCap( $fldStru )
Description
- Returns the column caption (display label) defined in a field's structure.
- Use to label columns/inputs consistently with the table definition.
Parameters
- <$fldStru>: Structure of the field
Returns
- String โ the field's caption.
Return example
$cap = ColCap($fldStru);
// e.g. 'Order No'
Usage example
$cap = ColCap('chlno');
:material-file-code: Source: apis/core2_a.php
generateAutoSerial4UniqueField()
Prototype
generateAutoSerial4UniqueField( $cTable='' )
Description
- Generates the next serial number for a table's unique-field definition, honouring its format rules.
- Reads POST variables at runtime so prefixes/series based on other fields resolve correctly.
Parameters
- <$cTable>: Table name
Returns
- Number/string โ the next value satisfying the unique criteria.
Return example
$no = generateAutoSerial4UniqueField('trn_salesorder');
// e.g. 'SO/2024/1043'
Usage example
$lNewSr = generateAutoSerial4UniqueField( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getCompoundUnique()
Prototype
GetCompoundUnique( $cTable='' )
Description
- Returns the table's compound (multi-column) unique keys with structures.
- Use to validate uniqueness across a combination of fields.
Parameters
- <$cTable>: Name of table
Returns
- Array โ compound unique field sets with their structures.
Return example
$c = getCompoundUnique('trn_salesorderg');
// [ ['linkid','feeder'], ... ]
Usage example
$aUnq = GetCompoundUnique( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getFieldStru()
Prototype
GetFieldStru( $cTable='', $field )
Description
- Returns the full structure definition of a single field (type, caption, link, flags, etc.).
- Use to drive dynamic rendering/validation based on a column's metadata.
Parameters
- <$cTable>: Name of table
- <$field>: Field name of which the structure is required
Returns
- Array โ the field's structure properties.
Return example
$s = getFieldStru('mst_item', 'rate');
// ['type'=>'N', 'caption'=>'Rate', 'dec'=>2, ...]
Usage example
$aTemp = GetFieldStru( 'trn_sales', 'party' );
:material-file-code: Source: apis/core2_a.php
getFieldsHavingAverage()
Prototype
getFieldsHavingAverage($cTable,$prefix='')
Description
- Returns the columns flagged with the AVG (average) property.
- Use to compute column averages in reports.
Parameters
- <$cTable> : string : Table name to be queried
- [$prefix] : string : any character(s) to be prefixed to column name
Returns
- Array โ column names that carry the AVG property.
Return example
$avgcols = getFieldsHavingAverage('trn_salesorderg');
// ['rate']
:material-file-code: Source: apis/core.php
getFieldsHavingCount()
Prototype
getFieldsHavingCount($cTable,$prefix='')
Description
- Returns the columns flagged with the COUNT property.
- Use to count occurrences in summarised reports.
Parameters
- <$cTable> : string : Table name to be queried
- [$prefix] : string : any character(s) to be prefixed to column name
Returns
- Array โ column names that carry the COUNT property.
Return example
$cntcols = getFieldsHavingCount('trn_salesorderg');
// ['takano']
:material-file-code: Source: apis/core.php
getFieldsHavingTotals()
Prototype
getFieldsHavingTotals($cTable,$prefix='',$form='')
Description
- Returns the columns of a table flagged with the SUM (total) property.
- Use to auto-total numeric columns in list reports.
Parameters
- <$cTable> : string : Table name to be queried
- [$prefix] : string : any character(s) to be prefixed to column name
- [$form] : string : unused
Returns
- Array โ column names that carry the SUM property.
Return example
$sumcols = getFieldsHavingTotals('trn_salesorderg');
// ['qty','amount']
:material-file-code: Source: apis/core.php
getFormTable()
Prototype
getFormTable( $cTable )
Description
- Returns the parent form/main table for a given table.
- If the table is itself the form (header) table, a blank is returned.
Parameters
- <$cTable>: Name of table
Returns
- String โ the form table name, or blank when the table is the form table.
Return example
$form = getFormTable('trn_salesorderg');
// e.g. 'trn_salesorder' (blank if already the header)
Usage example
$cFormTbl = getFormTable( 'trn_salesg' );
:material-file-code: Source: apis/core2_a.php
getGridAfter()
Prototype
GetGridAfter( $cTable, $fldAfter='' )
Description
- Returns the grid that should render after a specified field in a form layout.
- Used by the form renderer to interleave grids between header fields.
Parameters
- <$cTable>: Name of table
- <$fldAfter>: Field name after which to check
Returns
- Array โ grid info for the grid positioned after the given field.
Return example
$g = getGridAfter('trn_salesorder', 'customer');
// grid metadata or empty
Usage example
$gridinfo = GetGridAfter( 'trn_sales', 'agent' );
:material-file-code: Source: apis/core2_a.php
getGridTableNames()
Prototype
GetGridTableNames( $cTable )
Description
- Returns the names of the grid (child) tables attached to a form table, if any.
- Grids are the line-item tables under a header document.
Parameters
- <$cTable>: Name of table
Returns
- Array โ associated grid table name(s).
Return example
$grids = getGridTableNames('trn_salesorder');
// ['trn_salesorderg']
Usage example
$cGridTbls = GetGridTableNames( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getKeyField()
Prototype
GetKeyField( $cTable='' )
Description
- Returns the primary/key field name of a table.
- Use generically to build joins and id lookups without hard-coding the key.
Parameters
- <$cTable>: Name of table
Returns
- String โ the key field name of the table.
Return example
$key = getKeyField('mst_item');
// e.g. 'id'
Usage example
$aKeyfld = GetKeyField( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getOptionalField()
Prototype
GetFieldStru( $cTable='' )
Description
- Returns the names of all optional fields defined on a table.
- Optional fields are non-mandatory columns the project can choose to use.
Parameters
- <$cTable>: Name of table
Returns
- Array โ list of optional field names.
Return example
$opt = getOptionalField('mst_item');
// ['hsncode','remarks', ...]
Usage example
$aFields = GetOptionalField( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getPrintFile()
Prototype
getPrintFile( $cTable )
Description
- Returns the external print-template file associated with a table.
- Used by the print engine to pick the correct layout for a document.
Parameters
- <$cTable> : string : Table name to be queried
Returns
- String โ the print file name configured for the table.
Return example
$pf = getPrintFile('trn_salesorder');
// e.g. 'print_salesorder.php'
:material-file-code: Source: apis/core.php
getUniqueCharFields()
Prototype
GetUniqueCharFields( $cTable='' )
Description
- Returns only the string/character-type unique fields with their structures.
- Narrower form of
getUniqueFields()for text keys.
Parameters
- <$cTable>: Name of table
Returns
- Array โ unique character-type fields with structures.
Return example
$u = getUniqueCharFields('mst_item');
// [ ['field'=>'itemcode', ...] ]
Usage example
$aUnq = GetUniqueCharFields( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getUniqueFieldNames()
Prototype
GetUniqueFieldNames( $cTable='' )
Description
- Returns just the names of unique character fields (without structure detail).
- Lightweight when you only need the column names.
Parameters
- <$cTable>: Name of table
Returns
- Array โ unique character field names.
Return example
$names = getUniqueFieldNames('mst_item');
// ['itemcode']
Usage example
$aUnq = GetUniqueFieldNames( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
getUniqueFields()
Prototype
GetUniqueFields( $cTable='' )
Description
- Returns the table's unique fields together with their structures.
- Use for duplicate-checking and building natural-key lookups.
Parameters
- <$cTable>: Name of table
Returns
- Array โ unique fields, each with its structure definition.
Return example
$u = getUniqueFields('mst_item');
// [ ['field'=>'itemcode', 'stru'=>[...]], ... ]
Usage example
$aUnq = GetUniqueFields( 'trn_sales' );
:material-file-code: Source: apis/core2_a.php
gridRow()
Prototype
gridRow()
Description
- Returns the current grid row number as seen in the client browser.
- Useful inside grid post-validation/event code to know which line triggered it.
Parameters
- none
Returns
- Integer โ the active grid row index in the browser.
Return example
$r = gridRow();
// e.g. 3
Usage example
$nsecs = gridRow();
:material-file-code: Source: apis/core2.php
isDateField()
Prototype
isDateField( $aStru, $cField )
Description
- Checks whether a field is a date field within a table's structure array.
- Use to format/parse values correctly during generic processing.
Parameters
$aStruโ Standard Table Structure as returned from stru(...)$cFieldโ Field name to check
Returns
- Boolean โ
trueif the field is a date field.
Return example
if (isDateField($aStru, 'orderdate')) { ... }
// returns: true | false
Usage example
$stru = stru( 'trn_sales' );
$unq = isDateField( $stru, 'invdt' );
:material-file-code: Source: apis/core2_a.php
isFieldImage()
Prototype
isFieldImage($cTable, $field)
Description
- Checks whether a field stores an image.
- Use to render thumbnails/upload widgets for image columns.
Parameters
- <$cTable>: Name of table
- <$field>: field name to check
Returns
- Boolean โ
trueif the field is an image field.
Return example
if (isFieldImage('mst_item', 'photo')) { ... }
// returns: true | false
Usage example
$imagefld = isFieldImage('trn_sales', 'document');
:material-file-code: Source: apis/core2_a.php
isUniqueKey()
Prototype
isUniqueKey( $aStru, $cField )
Description
- Checks whether a field is a unique index within a table's structure array.
- Pass the structure (
$aStru) and field name to test.
Parameters
$aStruโ Standard Table Structure as returned from stru(...)$cFieldโ Field name to check
Returns
- Boolean โ
trueif the field is a unique key.
Return example
if (isUniqueKey($aStru, 'itemcode')) { ... }
// returns: true | false
Usage example
$stru = stru( 'trn_sales' );
$unq = isUniqueKey( $stru, 'invoice' );
:material-file-code: Source: apis/core2_a.php
stru()
Prototype
stru( $cTable )
Description
- Returns the complete structure of a table โ every column with all of its properties.
- Foundation for generic rendering, validation and metadata-driven tooling.
Parameters
- <$cTable> : string : Table name to be queried
Returns
- Array โ the full table structure (per-column property arrays).
Return example
$s = stru('mst_item');
// [ ['name'=>'itemname','type'=>'C',...], ... ]
:material-file-code: Source: apis/core.php
tableHasField()
Prototype
TableHasField( $cTable, $cField )
Description
- Checks whether a given field/column exists on a table.
- Use before referencing optional/customised columns that may not be present in every project.
Parameters
- <$cTable>: Table name
- <$field>: Field name to check
Returns
- Boolean โ
trueif the field exists on the table.
Return example
if (tableHasField('trn_salesorder', 'batchorder')) { ... }
// returns: true | false
Usage example
$lFld = TableHasField( 'trn_sales', 'agent' );
:material-file-code: Source: apis/core2_a.php
tabletitle()
Prototype
tabletitle( $cTable='', $pfolder='' )
Description
- Returns the display title of a table (its human-friendly module name).
- Use in headings and breadcrumbs.
Parameters
- <$cTable>: Name of table
- <$pfolder>: Leave blank
Returns
- String โ the table's title.
Return example
$t = tabletitle('trn_salesorder');
// e.g. 'Sales Order'
Usage example
$title = tabletitle('trn_sales');
:material-file-code: Source: apis/core2_a.php