Question
How can I pass an account identifier from an order page to the "Product in the order" detail edit page via sandbox messages?
Answer
The code of the order page replacing schema:
define("OrderPageV2", ["OrderPageV2Resources", "GeneralDetails"],
function(resources, GeneralDetails) {
return {
entitySchemaName: "Order",
details: /**SCHEMA_DETAILS*/{
}/**SCHEMA_DETAILS*/,
diff: /**SCHEMA_DIFF*/[
]/**SCHEMA_DIFF*/,
attributes: {},
methods: {
onEntityInitialized: function() {
this.callParent(arguments);
this.sandbox.subscribe("OrderProductPageAsksForData", function(arg) {
console.log("OrderProductPageV2 requests data immediately,");
console.log("по Id песочницы: " + arg.sandboxId);
// Sending data.
this.sendDataToOrderProductPage(arg.sandboxId);
}, this, [this.sandbox.id]);
console.log("Мы(OrderPageV2) subscribed to message: OrderProductPageAsksForData.");
console.log("sandbox Id in this page(OrderPageV2) next:");
console.log(this.sandbox.id);
},
sendDataToOrderProductPage: function(sandboxId) {
this.sandbox.publish("DataToOrderProductPage", { accountId: this.get("Account").value }, [sandboxId]);
console.log("AccountId sent as a message to OrderProductPageV2 по Id: " + sandboxId);
}
},
rules: {},
messages: {
"DataToOrderProductPage": {
mode: Terrasoft.MessageMode.PTP,
direction: Terrasoft.MessageDirectionType.PUBLISH
},
"OrderProductPageAsksForData": {
mode: Terrasoft.MessageMode.PTP,
direction: Terrasoft.MessageDirectionType.SUBSCRIBE
}
},
userCode: {}
};
});The code of the "Product in order" detail page replacing schema:
define("OrderProductPageV2", ["BusinessRuleModule", "OrderUtilities"],
function(BusinessRuleModule) {
return {
entitySchemaName: "OrderProduct",
mixins: {},
attributes: {},
methods: {
onEntityInitialized: function() {
this.callParent(arguments);
this.sandbox.subscribe("DataToOrderProductPage", function(arg) {
console.log("OrderPageV2 passes the data over to us!");
alert("accountId: " + arg.accountId);
}, this, [this.sandbox.id]);
console.log("Мы(OrderProductPageV2) subscribed to message: DataToOrderProductPage.");
console.log("По нашему(OrderProductPageV2) sandbox Id:");
console.log(this.sandbox.id);
this.sandbox.publish("OrderProductPageAsksForData", {
sandboxId: this.sandbox.id
}, [this.getOrderPageSandboxId()]);
console.log("Requested data from OrderPageV2, as per its sandbox Id: " + this.getOrderPageSandboxId());
},
getOrderPageSandboxId: function() {
var index = this.sandbox.id.indexOf("_detail_ProductInProducts");
return this.sandbox.id.substring(0, index);
}
},
messages: {
"DataToOrderProductPage": {
mode: Terrasoft.MessageMode.PTP,
direction: Terrasoft.MessageDirectionType.SUBSCRIBE
},
"OrderProductPageAsksForData": {
mode: Terrasoft.MessageMode.PTP,
direction: Terrasoft.MessageDirectionType.PUBLISH
}
},
diff: /**SCHEMA_DIFF*/[
]/**SCHEMA_DIFF*/,
rules: {
}
};
}
);