Front-end Creatio modules implement data management using the high-level EntitySchemaQuery class that builds database selection queries.
The major features of the EntitySchemaQuery class:
- Data selection queries created using EntitySchemaQuery apply the access permissions of the current user.
- The caching mechanism lets you optimize operations by accessing cached query results without direct access to the database.
The data management procedure for front-end Creatio modules is as follows:
- Create an instance of the EntitySchemaQuery class.
- Specify the root schema.
- Configure a path to the root schema column to add the column to the query.
- Create filter instances.
- Add the filters to the query.
- Filter the query results.
Configure the column paths relative to the root schema
Base an EntitySchemaQuery query on the root schema. The root schema is the database table relative to which to build paths to the query columns, including the columns of the joined tables. To use a table column in a query, set the path to the column correctly.
Specify the column path using direct connections
The template for configuring the column path using the direct connections of LookupColumnName.
For example, a [City] root schema contains a [Country] lookup column. The column is connected to the [Country] lookup schema via the Id column.
The path to the column that contains the name of the country connected to the city, built using the direct connections Country.Name. Where:
- Country is the name of the lookup column in the [City] root schema. Links to the [Country] schema.
- Name is the name of the column in the [Country] lookup schema.
Specify the column path using the reverse connections
The template for configuring the column path using the reverse connections [JoinableSchemaName:
The path to the column that contains the name of the contact who added the city, built using the reverse connections [Contact:Id:CreatedBy].Name. Where:
- Contact is the name of the joinable schema.
- Id is the name of the [Contact] schema’s column to connect the joinable schema.
- CreatedBy is the name of the [City] schema's lookup column to connect the current schema.
- Name is the value of the [City] schema's lookup column.
If the schema’s lookup column to connect the current schema is [Id], you do not have to specify it: [JoinableSchemaName:
Add the columns to the query
The EntitySchemaQuery query column is a Terrasoft.EntityQueryColumn class instance. Specify the main features in the column instance properties:
- header
- value for display
- usage flags
- sorting order and position
Add columns to the query using the addColumn() method that returns the query column instance. The addColumn() methods configure the name of the column relative to the root schema according to the rules described above: Configure the column paths relative to the root schema. The variations of the addColumn() method let you add query columns that contain different parameters. See the variations in the table below.
Column type | Method |
---|---|
The column by the specified path relative to the root schema | addColumn(column, columnAlias) |
The instance of the query column class | |
The parameter column | addParameterColumn(paramValue, paramDataType, columnAlias) |
The function column | addFunctionColumn(columnPath, functionType, columnAlias) |
The aggregative function column | addAggregationSchemaColumnFunctionColumn(columnPath, aggregationType, columnAlias) |
Retrieve the query results
The result of the EntitySchemaQuery query is a collection of Creatio entities. Each collection instance is a dataset string returned by the query.
The ways to retrieve the query results are as follows:
- Call the getEntity() method to retrieve a particular dataset string by the specified primary key.
- Call the getEntityCollection() method to retrieve the entire resulting dataset.
Manage the query filters
Filters are sets of conditions applied when displaying the query data. In SQL terms, a filter is a separate predicate (condition) of the WHERE operator.
To create a simple filter in EntitySchemaQuery, use the createFilter() method that returns the created object of the Terrasoft.CompareFilter filter. EntitySchemaQuery implements methods that create special kinds of filters.
The EntitySchemaQuery instance contains the filters property that represents the filter collection of the query (the Terrasoft.FilterGroup class instance). The Terrasoft.FilterGroup class instance is a collection of Terrasoft.BaseFilter elements.
Follow this procedure to add a filter to the query:
- Create a filter instance for the query (the createFilter() method, methods that create special kinds of filters).
- Add the filter instance to the query filter collection (the add() collection method).
By default, Creatio uses the logical AND operation to combine the filters added to the filters collection. The logicalOperation property of the filters collection lets you specify the logical operation for combining filters. The logicalOperation accepts the values of the Terrasoft.core.enums.LogicalOperatorType enumeration (AND, OR).
EntitySchemaQuery queries let you manage the filters involved in the creation of the resulting dataset. Each element of the filters collection includes the isEnabled property that determines whether the element takes part in building the resulting query (true/false). Creatio defines the similar isEnabled property for the filters collection. If you set this property to false, the query filtering will be disabled, yet the query filters collection will remain unchanged. Thus, you can create a query filters collection and use various combinations without modifying the collection directly.
Configure the column paths in the EntitySchemaQuery filters according to the general rules for configuring the paths to columns relative to the root schema.
Column path relative to the root schema
- The root schema: [Contact].
- The column that contains the contact address: Address.
Column path that uses the direct connections
- The root schema: [Contact].
- The column that contains the account name: Account.Name.
- The column that contains the name of the account’s primary contact: Account.PrimaryContact.Name.
Column path that uses the reverse connections
- The root schema: [Contact].
- The column that contains the name of the contact who added the city: [Contact:Id:CreatedBy].Name.
The EntitySchemaQuery class builds queries to select records in a database.
Methods
Aborts the query.
Creates an instance of the Terrasoft.FunctionQueryColumn function column with the specified AGGREGATION type. Adds the instance to the query column collection.
{String} column |
The path to the column to add, relative to rootSchema. |
{Terrasoft. |
The aggregate function type. Available values (Terrasoft.AggregationType)
The average of all elements. The number of elements. The maximal element. The minimal element. The aggregate function type is undefined. The sum of all elements. |
{String} column |
The column alias. Optional. |
{Terrasoft. |
The aggregate function scope. Available values (Terrasoft.AggregationEvalType)
The aggregate function scope is undefined. Apply to all elements. Apply to unique values. |
Creates an instance of the Terrasoft.EntityQueryColumn column. Adds the instance to the query column collection.
{String/Terrasoft. |
The path to the column to add (relative to rootSchema) or an instance of the Terrasoft.BaseQueryColumn query column. |
{String} column |
The column alias. Optional. |
{Object} config | The configuration object of the query column. |
Creates an instance of the Terrasoft.FunctionQueryColumn function column with the DATE_PART type. Adds the instance to the query column collection.
{String} column |
The path to the column to add, relative to rootSchema. |
{Terrasoft. |
The date part to use as the value. Available values (Terrasoft.DatePartType)
Empty value. Day. Week. Month. Year. Day of the week. Hour. Minute. |
{String} column |
The column alias. Optional. |
Creates an instance of the Terrasoft.FunctionQueryColumn function column with the MACROS type that must be parameterized. Adds the instance to the query column collection. For example, the following N days, the third quarter of the year, etc.
{Terrasoft. |
The column macro type. |
{Number/ |
The auxiliary variable for the macro. Optional. |
{String} column |
The column alias. Optional. |
Creates an instance of the Terrasoft.FunctionQueryColumn function column. Adds the instance to the query column collection.
{String} column |
The path to the column to add, relative to rootSchema. |
{Terrasoft. |
The function type. Available values (Terrasoft.FunctionType)
The functional expression type is undefined. The insertion that uses a macro. The aggregate function. The date part. The value size, in bytes. Use with binary data. |
{String} columnAlias | The column alias. Optional. |
Creates an instance of the Terrasoft.FunctionQueryColumn function column with the MACROS type that does not need to be parameterized. For example, current month, current user, primary column, etc. Adds the instance to the query column collection.
{Terrasoft. |
The column macro type. Available values (Terrasoft.QueryMacrosType)
The macro type is undefined. The current user. The current user contact. Yesterday. Today. Tomorrow. Previous week. Current week. Next week. Previous month. Current month. Next month. Previous quarter. Current quarter. Next quarter. Previous 6 months. Current 6 months. Next 6 months. Previous year. Current year. Previous hour. Current hour. Next hour. Next year. Next N days. Must be parameterized. Previous N days. Must be parameterized. Next N hours. Must be parameterized. Previous N hours. Must be parameterized. The primary column. The primary column for display. The primary column for image display. |
{String} column |
The column alias. Optional. |
Creates an instance of the Terrasoft.ParameterQueryColumn parameter column. Adds the instance to the query column collection.
{Mixed} param |
The parameter value. Must correspond to the data type. |
{Terrasoft. |
The parameter data type. |
{String} column |
The column alias. Optional. |
Creates a Between filter instance.
{Terrasoft. |
The expression to check in the filter. |
{Terrasoft. |
The initial expression of the filtering scope. |
{Terrasoft. |
The final expression of the filtering scope. |
Creates a Between filter instance to check if the column is within the specified scope.
{String} column |
The path to the check column, relative to the rootSchema root schema. |
{Mixed} less |
The initial value of the filter. |
{Mixed} greater |
The final value of the filter. |
{Terrasoft. |
The parameter data type. |
Creates a Compare filter to instance to compare the column to a specified value.
{Terrasoft. |
The comparison operation type. |
{String} column |
The path to the check column, relative to the rootSchema root schema. |
{Mixed} param |
The parameter value. |
{Terrasoft. |
The parameter data type. |
Creates an In filter instance to compare the value of a specified column to a parameter.
{String} column |
The path to the check column, relative to the rootSchema root schema. |
{Array} param |
The parameter value array. |
{Terrasoft. |
The parameter data type. |
Creates an IsNull filter instance to check the specified column.
{String} column |
The path to the check column, relative to the rootSchema root schema. |
Creates an IsNull filter instance to check the specified column.
{String} column |
The path to the check column, relative to the rootSchema root schema. |
Creates a Compare filter instance.
{Terrasoft. |
The comparison operation type. |
{Terrasoft. |
The expression to check in the filter. |
{Terrasoft.BaseExpression} rightExpression | The filtering expression. |
Creates an Exists filter instance for the [Exists by the specified condition] type comparison. Sets the expression of the column at the specified path as the check value.
{String} column |
The path to the column for whose expression to configure the filter. |
Creates an instance of the Terrasoft.CompareFilter class filter to compare the values of two columns.
{Terrasoft. |
The comparison operation type. |
{String} left |
The path to the check column, relative to the rootSchema root schema. |
{String} right |
The path to the filter column, relative to the rootSchema root schema. |
Creates a filter group instance.
Creates an In filter instance.
{Terrasoft. |
The expression to check in the filter. |
{Terrasoft. |
The array of expressions to compare to leftExpression. |
Creates an IsNull filter instance.
{Terrasoft. |
The expression to check by the IS NOT NULL condition. |
Creates an IsNull filter instance.
{Terrasoft. |
The expression to check by the IS NULL condition. |
Creates an Exists filter instance for the [Does not exist by the specified condition] type comparison. Sets the expression of the column located at the specified path as the check value.
{String} column |
The path to the column for whose expression to configure the filter. |
Creates a filter object to compare the primary column to a parameter.
{Terrasoft. |
The comparison type. |
{Mixed} param |
The parameter value. |
{Terrasoft. |
The parameter data type. |
Deletes the object instance. If the object has already been deleted, writes an error message to the console. Calls the onDestroy virtual method to redefine in subclasses.
Enables filters by the primary key.
{String/ |
The value of the primary key. |
Writes an error message to the message log.
{String} message | The error message to write to the message log. |
The request to execute the query on the server.
{Function} callback | The function to call after receiving the server response. |
{Object} scope | The scope within which to call the callback function. |
Returns the object that contains additional information for serialization.
Returns the entity instance by the specified primaryColumnValue primary key. Calls the callback function within the scope scope after retrieving the data.
{String/ |
The value of the primary key. |
{Function} callback | The function to call after receiving the server response. |
{Object} scope | The scope within which to call the callback function. |
Returns the collection of entity instances that represent the query outcome. Calls the callback function within the scope scope after retrieving the data.
{Function} callback | The function to call after receiving the server response. |
{Object} scope | The scope within which to call the callback function. |
Returns the information about the element type.
Writes a message to the message log.
{String| |
The message to write to the message log. |
{Terrasoft. |
The type of the callback message log. Optional. By default, console.log. The Terrasoft.core.enums.LogMessageType enumeration specifies the available values.. |
Deletes the event subscriptions and destroys the object.
Serializes the object in JSON.
{String} serialization |
The results in JSON. |
Assigns the property name to the object if the object is not empty or not a function.
{Object} serializable |
The serializable object. |
{String} property |
The property name. |
Writes a warning message to the message log.
{String} message | The message to write to the message log. |
DataManager class
DataManager is a singleton class available via the Terrasoft global object. The class provides the dataStore repository. You can upload the contents of one or more database tables to the repository.
Each record of the collection represents the record of the corresponding database table.
Properties
The data collection repository.
The record class name. Has the Terrasoft.DataManagerItem value.
Methods
If dataStore does not contain a data collection that has the config.entitySchemaName name, the method builds and executes a database query, then returns the retrieved data. Otherwise, the method returns the data collection from dataStore.
{Object} config |
The configuration object. Configuration object properties
The schema name. The conditions. |
{Function} callback | The callback function. |
{Object} scope | The scope of the callback function. |
Creates a new record of the config.entitySchemaName type. The record columns have the config.columnValues values.
{Object} config |
The configuration object. Configuration object properties
The schema name. The record column values. |
{Function} callback | The callback function. |
{Object} scope | The scope of the callback function. |
Adds the item record to the schema data collection.
{Terrasoft. |
The record to add. |
Returns the record from the data collection of the schema that has the entitySchemaName name and id ID.
{String} entity |
The data collection name. |
{String} id | The record ID. |
Selects the isDeleted flag for the item record. Once the changes are recorded, the record will be deleted from the database.
{Terrasoft. |
The record to delete. |
Deletes the record from the schema data collection.
{Terrasoft. |
The record to delete. |
Updates the record that has the config.primaryColumnValue primary column value with the values from config.columnValues.
{Object} config |
The configuration object. Configuration object properties
The schema name. The primary column value. The column values. |
{Function} callback | The callback function. |
{Object} scope | The scope of the callback function. |
Discards the changes to the item record made as part of the current DataManager session.
{Terrasoft. |
The record, changes to which to discard. |
Saves the data collections of the schemas specified in config.entitySchemaNames to the database.
{Object} config |
The configuration object. Configuration object properties
The name of the schema to save. Leave empty to save the data collections of all schemas. |
{Function} callback | The callback function. |
{Object} scope | The scope of the callback function. |
DataManagerItem class
Methods
Assigns the new columnValue value to the column that has the columnName name.
{String} column |
The column name. |
{String} column |
The column value. |
Returns the value of the column that has the columnName name.
{String} column |
The column name. |
Returns the values of all record columns.
Selects the isDeleted flag for the record.
Discards the changes to the record made as part of the current DataManager session.
Records the changes in the database.
{Function} callback | The callback function. |
{Object} scope | The scope of the callback function. |
Returns the flag that marks the record as new.
Returns the flag that marks the record as changed.