Read records in the section using DataService
In the Contacts section, add a button which will open the method that will use DataService to read records in the Contacts section with the following columns:
Id
;Full name
;Number of activities
– aggregate column, which displays the number of activities of this contact.
Example implementation algorithm
1. Add a button in the Contacts section
Create a replacing client module of the Contacts section.
In the created client schema, add SelectQueryContactButtonCaption
localizable string and set its value to Select contacts.
Add a configuration object with the settings determining the button position to the diff
array.
//Setup of section button display.
diff: /**SCHEMA_DIFF*/[
// Properties for adding a custom button in a section.
{
// Indicates that an elementis added on a page.
"operation": "insert",
// Meta name of the parent control element where the button is added.
"parentName": "ActionButtonsContainer",
// Indicates that the button is added to the control element collection
// of parent element (meta-name specified in parentName).
"propertyName": "items",
// Meta-name of the added button.
"name": "SelectQueryContactButton",
// Additional properties of the element.
"values": {
// Type of added element - button.
itemType: Terrasoft.ViewItemType.BUTTON,
// Binding button title to a schema localizable string.
caption: { bindTo: "Resources.Strings.SelectQueryContactButtonCaption" },
// Binding of the button pressing handler method.
click: { bindTo: "onSelectQueryContactClick" },
"layout": {
"column": 1,
"row": 6,
"colSpan": 1
}
}
}
]/**SCHEMA_DIFF*/
2. Add handler method for the button pressing event
To enable reading the records when the button is clicked, add the following method to the methods
section of the replacing client schema:
methods: {
// Handler method for button click.
onSelectQueryContactClick: function() {
// Creating an instance of the Terrasoft.InsertQuery class.
var select = Ext.create("Terrasoft.EntitySchemaQuery", {
// Root schema name.
rootSchemaName: "Contact"
});
// Adding the [Full name] column to query.
select.addColumn("Name");
// Adding [Number of activities] aggregate column to a query.
select.addAggregationSchemaColumn(
// Path to column in relation to the root schema.
"[Activity:Contact].Id",
// Aggregation type – quantity.
Terrasoft.AggregationType.COUNT,
// Column title.
"ActivitiesCount",
// Aggregation function scope - for all elements.
Terrasoft.AggregationEvalType.ALL);
// Update query to server
// Getting whole collection of records and displaying it in the browser console.
select.getEntityCollection(function(result) {
if (!result.success) {
// Processing/logging of error.
this.showInformationDialog("Data query error");
return;
}
// Displayed message.
var message = "";
// Analyzing resulting collection and generating displayed message.
result.collection.each(function(item) {
message += "Full name: " + item.get("Name") +
". Number of activities: " + item.get("ActivitiesCount") + "\n";
});
// Displaying message in console.
window.console.log(message);
}, this);
}
}
Unlike the previous example, authentication is not needed in this case, because the program code is executed by Creatio directly.
In the client of the application core, there is not a class like the server core SelectQuery
class. To select data from a section, use the Terrasoft.EntitySchemaQuery
class. For more information on this class methods and properties are described in the API documentation.
Resources
Example implementation (GitHub)