How to use System Javascript Fields in User-Defined Javascript Functions

Description

Built-in system fields used for defining client-side expressions can be used in Javascript functions using the {grid.object}._getGridVariables method to get the variables from the Grid Component.

Discussion

When you define client-side expressions (e.g. calculated fields, show/hide expressions, enable expressions, dynamic images, conditional styles, etc.) you can use certain 'built-in' system fields in your expressions. However, when you define an arbitrary Javascript function you cannot use the system fields in your Javascript code. These system fields are:

System Field
Description
grid.rowState

Contains the state of the row. Value can be 'view', 'change', or 'enter'.

grid.isRowDirty

A true/false value indiciating if the row contains unsaved changes.

grid.isDirty

A true/false value indicating whether or not the Grid Component contains unsaved changes.

grid.pageNumber

The current active page number in the Grid Component.

grid.pagesInGrid

The number of pages in the Grid Component.

grid.logicalRecordNumber

The logical record number for the row.

grid.hasDetailView

A true/false value that indiciates whether or not the Grid Component has a detail view.

grid.isOnFirstPage

A true/false value that indicates whether or not the current page of records is the first page in the Grid Component.

grid.isOnLastPage

A true/false value that indicates whether or not the current page of records is the last page in the Grid Component.

grid.hasNextPage

A true/false value that indicates if there is a next page to navigate to from the current page in the Grid Component.

grid.hasPrevPage

A true/false value that indicates if there is a previous page to navigate to from the current page in the Grid Component.

grid.isNewRecordRow

A true/false value that indicates whether or not the row is a new record row.

grid.checkedRowCount

The number of checked rows in a Grid Component with a Checkbox Selector Column.

grid.rowIsChecked

A true/false value that, for a Grid Component with a Checkbox Selector Column, indicates whether or not the row is checked.

detailView.isDirty

A true/false value that indicates whether or not the detail view contains unsaved changes.

detailView.rowState

Contains the state of the row. Value can be 'view', 'change', or 'enter'.

detailView.isOnFirstRecord

A true/false value that indicates if this is the first record in the Grid Component.

detailView.isOnLastRecord

A true/false value that indiciates if this is the last record in the Grid Component.

detailView.hasNextRecord

A true/false value that indiciates if there is a record after this record in the Grid Component.

detailView.hasPrevRecord

A true/false value that indicates if there is a record before this record in the Grid Component.

detailView.mode

Contains the detail view's current mode. Values can be 'view', 'change', or 'enter'.

There may, however, be situations when you would like to refer to these system variables in your own Javascript function handlers.

You can do so, but you must first call a grid method to populate these system fields.

The following example show how you can use these system fields to create a button that will:

function myOwnUserDefinedFunction() {
    var detailView = {};
    var grid = {};
    //populate the 'system' variables
    {grid.object}._getGridVariables(grid,detailView);
 
    if(detailView.isDirty) {
        {grid.object}.submitDetailView();
    } else {
        location.href = 'mytargetpage.a5w';
    }
}
  1. Submit the Detail View to the server to save the current record if the record is dirty, or

  2. If the record is not dirty, will redirect to another page in your application.

After the record in the Detail View has been sucessfully saved, you can then redirect to your target page.

For example, in the 'afterDetailViewSubmit' system event, you could add this code:

if (e.hasErrors) { 
    location.href = 'mytargetpage.a5w';
}

See Also