Skip to main content
Version: 8.0

Create a new record in the section using DataService

Level: advanced
Example

Add to the Contacts section a button that when clicked invokes a method, using the InsertQuery class that adds a record with the following data:

  • Full name – John Best;
  • Full job title – Developer;
  • Business phone – +12 345 678 00 00.

Example implementation algorithm

1. Add button to the Contacts section

For this particular case, you need to create a replacement client module of the Contacts section.

In the created client schema, add the InsertQueryContactButtonCaption localizable string, and set the "Add contact" value to it.

Add a configuration object with the button location settings to the diff array.

diff
diff: /**SCHEMA_DIFF*/[
// Properties to be added to the custom button section.
{
// The element is added to the page.
"operation": "insert",
// Parent interface element name to which the button is added.
"parentName": "ActionButtonsContainer",
// The button is added to the interface element collection
// of the parent element (its metaname is specified in parentName).
"propertyName": "items",
// Added button metaname.
"name": "InsertQueryContactButton",
// Additional element properties.
"values": {
// Added element type – button.
itemType: Terrasoft.ViewItemType.BUTTON,
// Binding button caption to the localizable schema string.
caption: { bindTo: "Resources.Strings.InsertQueryContactButtonCaption" },
// Binding method of processing the button click.
click: { bindTo: "onInsertQueryContactClick" },
"layout": {
"column": 1,
"row": 6,
"colSpan": 1
}
}
}
]/**SCHEMA_DIFF*/

2. Add the processing method for the button click event

In order for a record with the necessary data to be added when a button created in the section is clicked, add the following method to the methods section of the replacement client schema:

methods
methods: {
// Method of processing the button click.
onInsertQueryContactClick: function() {
// Creating the Terrasoft.InsertQuery class instance.
var insert = Ext.create("Terrasoft.InsertQuery", {
// Root schema name.
rootSchemaName: "Contact"
});
// Setting the Terrasoft.ParameterExpression value-parameters.
// A value-parameter instance is created and added to the column value collection.
// Creating a value-parameter instance for the [Job title] column.
insert.setParameterValue("Name", "John Best", Terrasoft.DataValueType.TEXT);
// Creating a value-parameter instance for the [Business phone] column.
insert.setParameterValue("Phone", "+12 345 678 00 00", Terrasoft.DataValueType.TEXT);
// Creating a value-parameter instance for the [Job title] column.
insert.setParameterValue("Job", "11D68189-CED6-DF11-9B2A-001D60E938C6", Terrasoft.DataValueType.GUID);
// Data update query.
insert.execute(function(response) {
// Displaying server answer
window.console.log(response);
});
// Updating list data.
this.reloadGridData();
}
}
Important

Unlike the previous example, authorization is not required because the code is executed directly in the Creatio application.

The implementation of the InsertQuery class for the client part of the application kernel is different from the implementation of the InsertQuery in its back end. So, to create the parameters, the setParameterValue method is used, and for the query execution – the execute method. Learn about all the available properties and methods of the InsertQuery class implemented in the kernel client part in the API documentation.


Resources

GitHub (example implementation)

Button