Specific filtering of lookup field (Specific filtering of lookup field (Existings))

Congratulations. 

I have a task of filtering the reference field (Platform) by specific parameters in the page code.
Contact-Account-Licenses-Product-Platform.


In the SQL query, it looks like this:

select "Id", "Name" from "UsrPlatformList" as "platforms" 
	where 
		exists (select * from "Product" as "product" where  ("platforms"."Id") = ("product"."UsrPlatformId") and 
			exists (select * from "UsrLicenceClient" as "license" where ("product"."Id") = ("license"."UsrProductLicId") and 
			"license"."UsrAccountId" = '601cef3f-aa30-4fc0-b681-18d3e748ec65'
			)
		)

I'm trying to follow this instruction, but I can't.
I will be grateful for your help.

Like 1

Like

2 comments
Best reply

Ryan Farley,

I am sincerely grateful to you. With your help, other answers in the community and articles from the Academy, I learned and managed to write this complex filter. Thank you. The code currently looks like this:

attributes: {
	"UsrPlatform": {
		"dataValueType": Terrasoft.DataValueType.LOOKUP,
		"lookupListConfig": {
			"filter": function() {
				var platformFilter = this.Ext.create("Terrasoft.FilterGroup");
				var accountId = this.get("Account").value;
 
				var licenceFilter = Terrasoft.createExistsFilter(
					"[UsrLicenceClient:UsrProductLic].Id");
 
				licenceFilter.subFilters.addItem(
					Terrasoft.createColumnFilterWithParameter(
						Terrasoft.ComparisonType.EQUAL,
							"UsrAccount", accountId));
 
				var productFilter = Terrasoft.createExistsFilter(
					"[Product:UsrPlatform].Id", licenceFilter);
					platformFilter.addItem(productFilter);
				return platformFilter;
			}
		}
	}
}

I hope it helps someone and saves a lot of time.

 

You can create an exists filter by using something like the following. This example would get accounts where an activity exists with a particular owner.

// create the sub filter for the condition inside the exists
var subFilters = Terrasoft.createFilterGroup();
subFilters.addItem(Terrasoft.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Owner", "a6b4ea0c-420c-45ab-81e7-6e76c8cc15f7"));
 
// now create the exists filter and pass the sub filter conditions to it
// note, this second param of subFilters is optional if all you want is the exists without sub conditions
var existsFilter = Terrasoft.createExistsFilter("[Activity:Account].Id", subFilters);
esq.filters.addItem(existsFilter);

That is the equivalent to the following:

Ryan

Ryan Farley,

I am sincerely grateful to you. With your help, other answers in the community and articles from the Academy, I learned and managed to write this complex filter. Thank you. The code currently looks like this:

attributes: {
	"UsrPlatform": {
		"dataValueType": Terrasoft.DataValueType.LOOKUP,
		"lookupListConfig": {
			"filter": function() {
				var platformFilter = this.Ext.create("Terrasoft.FilterGroup");
				var accountId = this.get("Account").value;
 
				var licenceFilter = Terrasoft.createExistsFilter(
					"[UsrLicenceClient:UsrProductLic].Id");
 
				licenceFilter.subFilters.addItem(
					Terrasoft.createColumnFilterWithParameter(
						Terrasoft.ComparisonType.EQUAL,
							"UsrAccount", accountId));
 
				var productFilter = Terrasoft.createExistsFilter(
					"[Product:UsrPlatform].Id", licenceFilter);
					platformFilter.addItem(productFilter);
				return platformFilter;
			}
		}
	}
}

I hope it helps someone and saves a lot of time.

 

Show all comments