Introduction
One of the key sandbox mechanisms is module message exchange (see “Module message exchange”).
It often becomes necessary to publish and subscribe to the same message in different instances of the same class (module) or within the same schema inheritance hierarchy. To perform this the sandbox object has bidirectional messages that correspond to the value of the Terrasoft.MessageDirectionType.BIDIRECTIONAL enumeration.
Registration of bidirectional messages
To register bidirectional messages in the messages property of the schema, use the following confrontation object:
The purpose and possible values of the elements of configuration object used in message registration are described in the "Module message exchange” article.
Example of use
The following example demonstrates how bidirectional messages work.
The CardModuleResponse message is registered in the BaseEntityPage schema, which is a base schema for all view model schemas of the record edit pages.
For example, the message is published after saving the modified record.
This functionality is implemented in the BasePageV2 child schema (i.e. the BaseEntityPage schema is parental for the BasePageV2 schema). Also, the LookupQuickAddMixin mixin is specified as a dependency in the BasePageV2. The subscription for the CardModuleResponse message is performed in this mixin.
Adding a new address on the contact edit page is a good example of how bidirectional messages work.
1. After executing the command of adding a new record on the Addresses detail. When will the timeline be finished? 1), the ContactAddressPageV2 module is loaded to the module chain and the edit page of the contact address opens.


The CardModuleResponse message has been already registered in the ContactAddressPageV2 schema as it has the BaseEntityPage and the BasePageV2 schemas in the inheritance hierarchy. This message is also registered in the_registerMessages() method of the LookupQuickAddMixin mixin at its initialization as the dependency module of the BasePageV2.
2. When adding the new value to the lookup fields of the ContactAddressPageV2 page (for example, a new city) the onLookupChange() method of the LookupQuickAddMixin mixin is called. In this method, in addition to loading the CityPageV2 module to the module chain, the_subscribeNewEntityCardModuleResponse() methodis called, in which the subscription for the CardModuleResponse message is performed. After this, the city edit page is opened (the CityPageV2).

3. As the CityPageV2 schema also has the BasePageV2 schema in the inheritance hierarchy, the onSaved() method implemented in the base schema will be executed after saving the record (the Save button). This method calls the sendSaveCardModuleResponse() method where the message (CardModuleResponse) is published. At the same time, the object with the necessary saving results is passed.
4. The execution of the callback subscriber function that process results of saving a new city in the lookup starts after publication of the message (see the _subscribeNewEntityCardModuleResponse() method of the LookupQuickAddMixin mixin).
The publication and subscription for the bidirectional message was performed in one inheritance hierarchy of the schemas with the BasePageV2 base schema that contains all necessary functions.