Getting query result
Glossary Item Box
The EntitySchemaQuery query result is a bpm'online property collection. Each instance of a collection is a string of a data set, returnable by query. You can get query results in the following ways:
- Get a definite string of a data set by a primary key through calling the getEntity method (example 1).
- Get entire resultant data set by calling getEntityCollection method (example 2).
Example 1. — Getting a definite data set string
// Get [Id] of card object. var recordId = this.get("Id"); // Create Terrasoft.EntitySchemaQuery class instance with [Contact] root schema. var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Contact" }); // Add column with name of main contact of accounts that refers to given contact. esq.addColumn("Account.PrimaryContact.Name", "PrimaryContactName"); // Get one record from selection on the basis of [Id] of card object and display it // in an info window. esq.getEntity(recordId, function(result) { if (!result.success) { // error processing/logging, for example this.showInformationDialog("Data query error"); return; } this.showInformationDialog(result.entity.get("PrimaryContactName")); }, this);
Example 2. — Getting entire data set
var message = ""; // Create Terrasoft.EntitySchemaQuery class instance with [Contact] root schema. var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "Contact" }); // Add column with account name that refers to given account. esq.addColumn("Account.Name", "AccountName"); // Add column with name of main contact account that refers to given contact. esq.addColumn("Account.PrimaryContact.Name", "PrimaryContactName"); // Get entire record colelction and display it in an infor window. esq.getEntityCollection(function (result) { if (!result.success) { // error processing/logging, for example this.showInformationDialog("Data query error"); return; } result.collection.each(function (item) { message += "Account name: " + item.get("AccountName") + " - primary contact name: " + item.get("PrimaryContactName") + "\n"; }); this.showInformationDialog(message); }, this);
Table 1. — Query result getting method
Method | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
getEntity(primaryColumnValue, callback, scope) |
returns entity instance on set primary key [primaryColumnValue]. It calls [callback] function in [scope] context after data receipt.
|
|||||||||
getEntityCollection(callback, scope) |
returns collection of entity instances that represent current query results. It calls [callback] function in [scope] context after data receipt.
|