Article
Filtering detail records based on selected record of other detail
02:14 Sep 19, 2018
Main detail code
define("UsrMasterDetail", [], function() { return { entitySchemaName: "Country", messages: { "RelatedDetailUpdateFilter": { mode: this.Terrasoft.MessageMode.PTP, direction: this.Terrasoft.MessageDirectionType.PUBLISH } }, methods: { onActiveRowChange: function() { var activeRow = this.get("ActiveRow"); var masterDetailRecordId = typeof activeRow === "object" ? activeRow && activeRow.value : activeRow; this.sandbox.publish("RelatedDetailUpdateFilter", masterDetailRecordId, [this.sandbox.id.replace(this.name, "MasterDetailRecordId")]); this.callParent(arguments); } } }; });
Related detail code
define("UsrRelatedDetail", [], function() { return { entitySchemaName: "City", messages: { "RelatedDetailUpdateFilter": { mode: this.Terrasoft.MessageMode.PTP, direction: this.Terrasoft.MessageDirectionType.SUBSCRIBE } }, attributes: { "MasterDetailRecordId": { "dataValueType": this.Terrasoft.DataValueType.GUID } }, methods: { init: function() { this.sandbox.subscribe("RelatedDetailUpdateFilter", function(masterDetailRecordId) { this.set("MasterDetailRecordId", masterDetailRecordId); this.setFilterByMasterRecord(masterDetailRecordId); this.reloadGridData(); }, this, [this.sandbox.id.replace(this.name, "MasterDetailRecordId")]); this.callParent(arguments); }, loadGridData: function() { if (this.get("MasterDetailRecordId")) { this.callParent(arguments); } else { this.onGridDataLoaded({success: true}); } }, setFilterByMasterRecord: function(masterDetailRecordId) { var filters = this.get("Filter"); filters.removeByKey("FilterByMasterDetail"); if (masterDetailRecordId) { filters.add("FilterByMasterDetail", this.Terrasoft.createColumnFilterWithParameter( this.Terrasoft.ComparisonType.EQUAL, "Country", masterDetailRecordId)); } } } }; });
Insert details into page
define("ContactPageV2", [], function() { return { entitySchemaName: "Contact", details: /**SCHEMA_DETAILS*/{ "UsrMasterDetail": { "schemaName": "UsrMasterDetail", "filterMethod": "getGlbDetailFilter" }, "UsrRelatedDetail": { "schemaName": "UsrRelatedDetail", "filterMethod": "getGlbDetailFilter" } }/**SCHEMA_DETAILS*/, diff: /**SCHEMA_DIFF*/[ { "operation": "insert", "name": "UsrMasterDetail", "values": { "itemType": this.Terrasoft.ViewItemType.DETAIL }, "parentName": "GeneralInfoTab", "propertyName": "items" }, { "operation": "insert", "name": "UsrRelatedDetail", "values": { "itemType": this.Terrasoft.ViewItemType.DETAIL }, "parentName": "GeneralInfoTab", "propertyName": "items" } ]/**SCHEMA_DIFF*/, methods: { getGlbDetailFilter: function() { var filterGroup = new this.Terrasoft.createFilterGroup(); return filterGroup; } } }; });
Result:
19:09 Nov 02, 2020
Hello Tatiana,
This is still working in the last versions of creatio?
16:37 Nov 03, 2020
Hello Federico,
Thank you for your interest!
There were implemented some updates and for now, the code looks like it's described below:
Main detail code
define("UsrMasterDetail", [], function() { return { entitySchemaName: "Country", messages: { "RelatedDetailUpdateFilter": { mode: this.Terrasoft.MessageMode.PTP, direction: this.Terrasoft.MessageDirectionType.PUBLISH } }, methods: { onActiveRowChange: function() { var activeRow = this.get("ActiveRow"); var masterDetailRecordId = typeof activeRow === "object" ? activeRow && activeRow.value : activeRow; var detailId = this.sandbox.id.replace(this.name, "MasterDetailRecordId"); detailId = detailId.replace(this.entitySchemaName, ""); this.sandbox.publish("RelatedDetailUpdateFilter", masterDetailRecordId, [detailId, this.sandbox.id]); this.callParent(arguments); } } }; });
Related detail code
define("UsrRelatedDetail", [], function() { return { entitySchemaName: "City", messages: { "RelatedDetailUpdateFilter": { mode: this.Terrasoft.MessageMode.PTP, direction: this.Terrasoft.MessageDirectionType.SUBSCRIBE } }, attributes: { "MasterDetailRecordId": { "dataValueType": this.Terrasoft.DataValueType.GUID } }, methods: { subscribeSandboxEvents: function() { this.callParent(arguments); var detailId = this.sandbox.id.replace(this.name, "MasterDetailRecordId"); detailId = detailId.replace(this.entitySchemaName, ""); this.sandbox.subscribe("RelatedDetailUpdateFilter", function(masterDetailRecordId) { this.set("MasterDetailRecordId", masterDetailRecordId); this.setFilterByMasterRecord(masterDetailRecordId); this.reloadGridData(); }, this, [detailId]); }, loadGridData: function() { if (this.get("MasterDetailRecordId")) { this.callParent(arguments); } else { this.onGridDataLoaded({success: true}); } }, setFilterByMasterRecord: function(masterDetailRecordId) { var filters = this.get("Filter"); filters.removeByKey("FilterByMasterDetail"); if (masterDetailRecordId) { filters.add("FilterByMasterDetail", this.Terrasoft.createColumnFilterWithParameter( this.Terrasoft.ComparisonType.EQUAL, "Country", masterDetailRecordId)); } } } }; });
Insert details into the page
define("ContactPageV2", [], function() { return { entitySchemaName: "Contact", details: /**SCHEMA_DETAILS*/{ "UsrMasterDetail": { "schemaName": "UsrMasterDetail", "filterMethod": "getGlbDetailFilter" }, "UsrRelatedDetail": { "schemaName": "UsrRelatedDetail", "filterMethod": "getGlbDetailFilter" } }/**SCHEMA_DETAILS*/, diff: /**SCHEMA_DIFF*/[ { "operation": "insert", "name": "UsrMasterDetail", "values": { "itemType": this.Terrasoft.ViewItemType.DETAIL }, "parentName": "GeneralInfoTab", "propertyName": "items" }, { "operation": "insert", "name": "UsrRelatedDetail", "values": { "itemType": this.Terrasoft.ViewItemType.DETAIL }, "parentName": "GeneralInfoTab", "propertyName": "items" } ]/**SCHEMA_DIFF*/, methods: { getGlbDetailFilter: function() { var filterGroup = new this.Terrasoft.createFilterGroup(); return filterGroup; } } }; });
The result will be the same:
Also before providing any changes in schemas we suggest to save original schemas as backups.
Best regards,
Roman
Show all comments