Skip to main content
Version: 8.1

Example that uses bidirectional messages

Level: intermediate

The BaseEntityPage schema of the CrtNUI package registers the CardModuleResponse message. The BaseEntityPage schema is the base schema of the record page’s view model.

BaseEntityPage
define("BaseEntityPage", [...], function(...) {
return {
messages: {
...
"CardModuleResponse": {
"mode": this.Terrasoft.MessageMode.PTP,
"direction": this.Terrasoft.MessageDirectionType.BIDIRECTIONAL
},
...
},
...
};
});

For example, Creatio publishes a message after saving the modified record. The BasePageV2 child schema of the CrtNUI package implements this functionality.

BasePageV2
define("BasePageV2", [..., "LookupQuickAddMixin", ...], function(...) {
return {
...
methods: {
...
onSaved: function(response, config) {
...
this.sendSaveCardModuleResponse(response.success);
...
},
...
sendSaveCardModuleResponse: function(success) {
var primaryColumnValue = this.getPrimaryColumnValue();
var infoObject = {
action: this.get("Operation"),
success: success,
primaryColumnValue: primaryColumnValue,
uId: primaryColumnValue,
primaryDisplayColumnValue: this.get(this.primaryDisplayColumnName),
primaryDisplayColumnName: this.primaryDisplayColumnName,
isInChain: this.get("IsInChain")
};
return this.sandbox.publish("CardModuleResponse", infoObject, [this.sandbox.id]);
},
...
},
...
};
});

The LookupQuickAddMixin mixin is listed in the BasePageV2 schema as a dependency. The mixin implements the subscription to the CardModuleResponse message. Learn more in a separate article: Client schema.

LookupQuickAddMixin
define("LookupQuickAddMixin", [...], function(...) {
Ext.define("Terrasoft.configuration.mixins.LookupQuickAddMixin", {
alternateClassName: "Terrasoft.LookupQuickAddMixin",
...
/* Declare the message. */
_defaultMessages: {
"CardModuleResponse": {
"mode": this.Terrasoft.MessageMode.PTP,
"direction": this.Terrasoft.MessageDirectionType.BIDIRECTIONAL
}
},
...
/* Register the message. */
_registerMessages: function() {
this.sandbox.registerMessages(this._defaultMessages);
},
...
/* Initialize a class instance. */
init: function(callback, scope) {
...
this._registerMessages();
...
},
...
/* Execute after adding a new record to a lookup. */
onLookupChange: function(newValue, columnName) {
...
/* Execute a chain of method calls.
As a result, the _subscribeNewEntityCardModuleResponse() method is called. */
...
},
...
/* The method that subscribes to the "CardModuleResponse" message.
The callback function sets the lookup field to the value sent when the message was published. */
_subscribeNewEntityCardModuleResponse: function(columnName, config) {
this.sandbox.subscribe("CardModuleResponse", function(createdObj) {
var rows = this._getResponseRowsConfig(createdObj);
this.onLookupResult({
columnName: columnName,
selectedRows: rows
});
}, this, [config.moduleId]);
},
...
});
return Terrasoft.LookupQuickAddMixin;
});

The procedure that handles bidirectional messages when adding a new address to a contact page is as follows:

  1. Creatio loads the ContactAddressPageV2 module into the module chain on the Addresses detail.

  2. The contact address page is opened.

    Since the ContactAddressPageV2 schema inherits the BaseEntityPage and BasePageV2 schemas, the ContactAddressPageV2 schema already has the CardModuleResponse message registered. This message is also registered in the _registerMessages() method of the LookupQuickAddMixin mixin when the mixin is initialized in the BasePageV2 schema as a dependency.

  3. The onLookupChange() method of the LookupQuickAddMixin mixin is called when adding a new value, for example, a city, to the lookup fields of the ContactAddressPageV2 page.

  4. The CityPageV2 module is loaded into the module chain.

  5. The onLookupChange() method calls the _subscribeNewEntityCardModuleResponse() method that subscribes to the CardModuleResponse message.

  6. The city page (CityPageV2 schema in the CrtUIv2 package) is opened.

  7. Since the CityPageV2 schema inherits the BasePageV2 schema, the onSaved() method of the base schema is executed after the user saves the record ( Save button).

  8. The onSaved() method calls the sendSaveCardModuleResponse() method that publishes the CardModuleResponse message. At the same time, the object that contains the necessary results of saving is passed.

  9. After the message is published, the callback function (_subscribeNewEntityCardModuleResponse() method in the LookupQuickAddMixin mixin) of the subscriber is executed. The method processes the results of saving the new city to the lookup.

Thus, publishing and subscribing to a bidirectional message are executed as part of a single schema inheritance hierarchy. In this hierarchy, the BasePageV2 base schema contains all required functionality.