Creatio development guide
PDF
This documentation is valid for Creatio version 7.16.0. We recommend using the newest version of Creatio documentation.

The EntitySchemaQuery class. Getting query result

Glossary Item Box

The EntitySchemaQuery query result is a Creatio 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);

When retrieving the lookup columns, this.get() method returns object but not the database record identifier. To access identifier, use the "value" property, for example, this.get('Account').value.

Table 1. — Query result getting method

Method
getEntity(primaryColumnValue, callback, scope)

returns entity instance on set primary key [primaryColumnValue]. It calls [callback] function in [scope] context after data receipt.

primaryColumnValue String/Number Is a primary key value.
callback Function Is a function, called upon receipt of server response.
scope Object Context where [callback] function will be called.
getEntityCollection(callback, scope)

returns collection of entity instances that represent current query results. It calls [callback] function in [scope] context after data receipt.

callback Function Is a function that will be called upon receipt of server response.
scope Object Is a context where [callback] function will be called.

See Also

© Creatio 2002-2020.

Did you find this information useful?

How can we improve it?