How to apply filter in Product detail of order section (ProductSelectionSchema) | Filters not working

Hi Team,


We have a scenario to display only few products when the add (+) icon is clicked in the Product detail of Order section. When the add record is clicked a product catalogue is displayed.

Required Filter Scenario:
All the products that belong to a particular price list alone should be shown in the product catalogue list along with additional columns in the Product Price table is also taken into consideration for the filter.


Only Products that match the below conditions should be displayed in the list,

  1. Particular Price List.
  2. Particular column value in Product Price (Custom Column ex: UsrProductGrade).
  3. Particular column value in Product Price (Custom Column ex: UsrIsActive).


Required Default Value in UOM Lookup:

When the product catalogue page is opened the UOM (Unit of Measure) field should be set with a particular lookup value by default available in that lookup & set to locked (not editable).


Filter out/Remove/Hide all product's base prices in the product catalogue

Don't want any base price in the product price and not needed to show this record in the product catalogue.


Below is the setup for the above case:
Step 1: Filter applied in ProductSelectionSchema (Not Working)

getProductInBasePriceListEsq: function(basePriceList) {
			var basePriceListProductEsq = this.getBaseESQ("Product");
			var customPriceList = Terrasoft.SysSettings.cachedSettings.UsrcustomPriceList;
			var productPricePrefix = "[ProductPrice:Product:Id].";
			basePriceListProductEsq.rowCount = 40;
			var productGrade = this.sandbox.publish("productGradeMessage", null, "productFilterGradeMessage");
			basePriceListProductEsq.addColumn("Price", "ProductPrice");
			basePriceListProductEsq.addColumn(productPricePrefix + "Price", "Price");
			basePriceListProductEsq.addColumn(productPricePrefix + "Currency", "Currency");
			basePriceListProductEsq.addColumn(productPricePrefix + "Tax", "Tax");
			basePriceListProductEsq.addColumn(productPricePrefix + "Tax.Percent", "DiscountTax");
			basePriceListProductEsq.addColumn(productPricePrefix + "PriceList", "PriceList");
			basePriceListProductEsq.addColumn(productPricePrefix + "UsrProductGrade", "UsrProductGrade");
			basePriceListProductEsq.addColumn(productPricePrefix + "UsrIsActive", "UsrIsActive");
			//Additional Filters for Grade and Active product
				this.Terrasoft.ComparisonType.EQUAL, productPricePrefix + "PriceList.Id", customPriceList));	
				this.Terrasoft.ComparisonType.EQUAL, productPricePrefix + "UsrProductGrade", productGrade.value));
				this.Terrasoft.ComparisonType.EQUAL, productPricePrefix + "UsrIsActive", true));
					"IsArchive", false));
			return basePriceListProductEsq;


Step 2:  Made the value "Base" inactive from pricelist lookup (still all the products base price list is shown).


None of the filters applied is working. Instead, it shows the products that are matched with new pricelist value in the pricelist lookup for other products which doesn't has new value it takes the base price list and displays.

Any insight on this would be highly appreciated!



Bhoobalan Palanivelu.

Like 0



Hello Bhoobalan,


Maybe it's much easier to modify the logic of the onGridDataLoaded method in the ProductSelectionSchema module and modify the final gridData collection that will be displayed? When the grid data is loaded in the context of execution of this method you can check all records loaded to this selection page one by one and check whether they have the needed price list (and if so leave it in the grid data, othewise remove this record from grid data) and also you can apply modifications to such records (like setting the default unit of measure). Because creating custom ESQ that is asynchronous can result in inconsistent behavior and also to errors when loading the grid.

Oleg Drobina,


It would be of great help if you could assist with a simple sample for this case in the Product selection schema.

And how to set a default value for a Unit Of Measure field and make it locked?

BBhoobalan Palanivelu.

Bhoobalan Palanivelu,


to lock the "Unit Of Measure" column you need to override the getEditableColumns method in the ProductSelectionSchema module. For example like in the example below:

getEditableColumns: function() {
				let parentColumns = this.callParent(arguments);
				if (this.Terrasoft.isCurrentUserSsp()) {
					parentColumns = this.Terrasoft.without(parentColumns, "Price");
				parentColumns = this.Terrasoft.without(parentColumns, "Unit");
				return parentColumns;

As a result you won't be able to modify the Unit Of Measure" column.


As for settings the removing some results from the grid: for example I have two products in the selection window: one has the price of 900 and another one has the price of 100. I want to remove the product with the price that is less or equal 100. To do so we override the onGridDataLoaded method in the following manner:

onGridDataLoaded: function(response) {
				if (!response.success || response.queryResults.length === 0) {
				var dataCollection = this.Ext.create("Terrasoft.Collection");
				this.prepareResponseCollection(dataCollection, response);
				var lastValue = null;
				var gridData = this.getGridData();
				var canLoadData = false;
				for (var i=0; i < dataCollection.getItems().length; i++) {
					var price = dataCollection.getItems()[i].values.Price;
					if (price <= 100) {
				if (dataCollection.getCount()) {
					var lastItemIndex = dataCollection.getCount() - 1;
					var lastItem = dataCollection.getByIndex(lastItemIndex);
					var products = gridData.collection.filterBy(
						function(res) {
							var resId = res.get("RealRecordId");
							return resId === lastItem.get("RealRecordId");
					if ((products.length <= 0)) {
						lastValue = lastItem.get("Name");
						canLoadData = true;
				this.set("sortColumnLastValue", lastValue);
				if (canLoadData) {
				this.set("GridData", gridData);

the main body of the method is a basic body and the customization here goes at:

for (var i=0; i < dataCollection.getItems().length; i++) {
					var price = dataCollection.getItems()[i].values.Price;
					if (price <= 100) {

where we prepare received data collection for further basic processing. So you can test this approach on your side.

Oleg Drobina,

Appreciate the detailed response!

How shall we set some particular/specific value as the default value to this Unit Of Measure (UOM) lookup field?

We have locked it in getEditableColumns() and how does the logic go by to set a default value?

Best Regards,
Bhoobalan Palanivelu.

Bhoobalan Palanivelu,


this is the custmization inside the onGridDataLoaded method, but additionally to the previous removal of records we will need to set the value for the "Unit of measure" column for each record after the unnecessary records are removed from the dataCollection.

Oleg Drobina,

Thanks for the response!

Still, the filter remains not to work even with the logic of removing values from the collection in OnGridDataLoaded().


The code gets executed but still, the products with 0 prices are shown in the Grid. please find the below references.


Logic es executing:


All records are again loaded into the Grid 



Bhoobalan Palanivelu.

Bhoobalan Palanivelu,


I've checked and indeed it happens in case there are two records with the price = 0 that are located one after another in the dataCollection (for example the 0 item has 0 price and the 1st item has 0 price). It happens because the logic removes an item with the 0 index (i=0), as a result an item with the 1 index is moved to the 0 index (because the original item with 0 index was deleted) and since we are in a cycle the code goes to check the item with the 1 index and skips that item that moved to the 0 index.


Perhaps this dataCollection should be processed in terms of a separate collection and then this custom collection should be placed into the dataCollection.

Show all comments