Article
Passing a value (message) from the detail schema to the detail page
17:35 Jul 19, 2018
Question
Receiving messages does not work. Version 7.7.
methods: { editRecord: function(editPageUId) { this.callParent(arguments); var text = "ilaySchema6Detail"; this.sandbox.publish("PublishDetailName", text); } }, messages: { "PublishDetailName": { "mode": this.Terrasoft.MessageMode.BROADCAST, "direction": this.Terrasoft.MessageDirectionType.PUBLISH } }
methods: { subscribeSandboxEvents: function() { this.callParent(arguments); this.sandbox.subscribe("PublishDetailName", this.getDetailNameFromWhoOpen, this); }, getDetailNameFromWhoOpen: function(detailName) { var a = 5; } }, messages: { "PublishDetailName": { "mode": this.Terrasoft.MessageMode.BROADCAST, "direction": this.Terrasoft.MessageDirectionType.SUBSCRIBE } }
The getDetailNameFromWhoOpen() method cannot be called.
Answer
The issue is that you publish the message before (!) the detail edit page is open. When the page is open, you perform subscription. But the moment is lost. You subscribe to the message when noone will publish it.
You need to execute publish on the edit page, taking the result as a variable.
In the detail schema, execute subscribe, whose handler must be the function returning the value.
Example.
Detail schema:
define("ilaySchema6Detail", [], function() { return { entitySchemaName: "ilayRecomendation", details: /**SCHEMA_DETAILS*/{ }/**SCHEMA_DETAILS*/, diff: /**SCHEMA_DIFF*/[ ]/**SCHEMA_DIFF*/, methods: { addRecord: function(editPageUId) { this.callParent(arguments); }, init: function() { this.callParent(arguments); console.log("id in detail: " + this.sandbox.id); this.sandbox.subscribe("PublishDetailName", this.getDetailNameFromWhoOpen, this, [this.sandbox.id] ); }, getDetailNameFromWhoOpen: function() { return { param: "test!" }; } }, messages: { "PublishDetailName": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.SUBSCRIBE } } }; });
Page schema:
define("ilayilayRecomendation1Page", [], function() { return { entitySchemaName: "ilayRecomendation", details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/, diff: /**SCHEMA_DIFF*/[ ]/**SCHEMA_DIFF*/, methods: { onEntityInitialized: function() { this.callParent(arguments); var res = this.sandbox.publish("PublishDetailName", null, [this.getDetailId()] ); alert(res.param); }, getDetailId: function() { var index = this.sandbox.id.indexOf("ilayilayRecomendation1Page"); var newId = this.sandbox.id.substring(0, index); console.log("id in page: " + newId); return newId; }, }, rules: {}, messages: { "PublishDetailName": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.PUBLISH } }, attributes: { } }; });