We have a project where I need to filter a certain lookup by a few booleans, where another lookup has the same booleans and only the true values need to be taken into consideration when filtering, unfortunatley with business rules, it will compare the false ones as well which causes only records whos booleans 100% match the ones in the other lookup to show, I have the following code to filter it, but it doesn't seem to work properly, I tried to debug it, but can't seem to find the issue.
attributes: { "UniChargeType": { "dataValueType": Terrasoft.DataValueType.LOOKUP, "lookupListConfig": { "filter": function() { var priceTemplate = this.get("UniUniPriceTemplate"); var esqCharge = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName:"UniChargeType" }); esqCharge.addColumn("UniAir"); esqCharge.addColumn("UniOcean"); esqCharge.addColumn("UniInland"); var esqChargeFirstFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniAir", true); var esqChargeSecondFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniOcean", true); var esqChargeThirdFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniInland", true); esqCharge.filters.logicalOperation = Terrasoft.LogicalOperatorType.OR; esqCharge.filters.add("esqChargeFirstFilter", esqChargeFirstFilter); esqCharge.filters.add("esqChargeSecondFilter", esqChargeSecondFilter); esqCharge.filters.add("esqChargeThirdFilter", esqChargeThirdFilter); var esqTemplate = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName:"UniPriceTemplates" }); esqTemplate.addColumn("UniSubService.UniService.UniAir", "Air"); esqTemplate.addColumn("UniSubService.UniService.UniOcean", "Ocean"); esqTemplate.addColumn("UniSubService.UniService.UniInland", "Inland"); esqTemplate.addColumn("Id"); var templateFilter = esqTemplate.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id", priceTemplate); esqTemplate.filters.add("templateFilter", templateFilter); esqTemplate.getEntityCollection(function (result) {debugger; if (result.success){ if(result.collection.getByIndex(0).$Air == true){ var esqChargeFirstFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniAir", true); esqCharge.filters.add("esqChargeFirstFilter", esqChargeFirstFilter); esqTemplate.getEntityCollection(); return this; }else if (result.collection.getByIndex(0).$Ocean == true){ var esqChargeSecondFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniOcean", true); esqCharge.filters.add("esqChargeSecondFilter", esqChargeSecondFilter); esqTemplate.getEntityCollection(); return this; }else if (result.collection.getByIndex(0).$Inland == true){ var esqChargeThirdFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniInland", true); esqCharge.filters.add("esqChargeThirdFilter", esqChargeThirdFilter); esqTemplate.getEntityCollection(); return this; } result.collection.each(function(item) { result.collection.getByIndex(0).$Air if(item.entity.get("Air") == true){ var esqChargeFirstFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniAir", true); esqCharge.filters.add("esqChargeFirstFilter", esqChargeFirstFilter); }else if (item.entity.get("Ocean") == true){ var esqChargeSecondFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniOcean", true); esqCharge.filters.add("esqChargeSecondFilter", esqChargeSecondFilter); }else if (item.entity.get("Inland") == true){ var esqChargeThirdFilter = esqCharge.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "UniInland", true); esqCharge.filters.add("esqChargeThirdFilter", esqChargeThirdFilter); } }); } }, esqTemplate.getEntityCollection(), this); } } }
Like
The problem is that inside the lookupListConfig.filter you're doing an ESQ, and ESQs are asynchronous. So the filter is returned (which would be undefined or nothing) before the ESQ inside your code ever returns. You'll either need to rethink your filter and how to get the data you want, or prefetch the ESQ to UniChargeType earlier in the page lifecycle, like in the init and then store the results in an attribute, so they'll available to use when needed in the filter function.
Ryan