Skip to content

FourDCollection Class

Julio Carneiro edited this page Mar 14, 2020 · 4 revisions

A service class that represents a collection of 4D records. It is basically an Array of FourDModel instances.

Instances of this class represent a 4D Database record set.

This class provides the following public properties:

  • model: FourDModel class whose instances populate the record set array
  • models: the Array of FourDModel instances representing a record set
  • queryString: a default Query String, used when no actual query is provided
  • filterOptions: a default Filter Options to apply on all record retrievals, thus setting an additional criteria for all records in the collection; can be replaced on a getRecords() call
  • orderBy: a default Order By, so that records are retrieved from 4D in a specific sort order
  • totalRecordCount: the number of records found in the last query

The FourDCollection class provides the following public functions:

getRecords() Function

Use this function to retrieve a list of records from a 4D Database, populating the FourDCollection's instance record set. It sends a REST_GetRecords request to 4D, and uses the response to populate the record set array.

The function call takes up to 6 arguments, all optional, except for the first one:

  • query: a Query String with the criteria for the desired record selection to retrieve
  • columns: an Array listing the fields to retrieve for each record; if present only those fields will be retrieved, not the entire record
  • startRec: the index of the first record from the record selection to return; default is 0, the first record
  • numOfRecords: the maximum number of records to retrieve (used for paging); default is -1, meaning no maximum set, retrieve all selected records (from the startRec point)
  • filterOptions: an additional Query String, to further reduce the resulting record selection; if set, the resulting record selection will have to meet both the query and the filterOptions criteria; if null, the default filterOptions will be used; if blank, then it'll override the default filterOptions
  • orderBy: optional Order By clause to retrieve records in a desired sort order.
    • >table.field : to sort records by table.field in ascending order
    • <table.field : to sort records by table.field in descending order

The function returns a Promise, which the caller can subscribe to in order to perform some action after the record set is received. The Promise result is the FourDModels Array retrieved from 4D.

bulkDelete() Function

Use this function to delete a set of records from a 4D Database, that match a given query. It sends a REST_BulkDelete request to 4D.

The function call takes up to 3 arguments, all optional, except for the first two:

  • tableName: the table name to apply the given query, and whose records will be deleted from.
  • query: a Query String with the criteria for the desired record selection to delete
  • filterOptions: an additional Query String, to further reduce the resulting record selection; if set, the resulting record selection will have to meet both the query and the filterOptions criteria; if null, the default filterOptions will be used; if blank, then it'll override the default filterOptions

The function returns a Promise, which the caller can subscribe to in order to perform some action after the record set is deleted. The Promise result is a JSON object that indicates if the deletion was completed successfully, and the actual number of records deleted, see REST_BulkDelete for details.