How can I filter a field by the "Exists " filter with a parameter (another field value)

Question

How can I filter a field by the "Exists " filter with a parameter (another field value)?

Answer

Example of implementation the "Exists " filter:

var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {
    "rootSchemaName": "Account"
});
// add the request columns
esq.addColumn("Id");
...
// filtering condition for using inside of "exists"
// searchValue - value for comparing with the SearchNumber column
var subFilters = Terrasoft.createFilterGroup();
subFilters.addItem(Terrasoft.createColumnFilterWithParameter(
    Terrasoft.ComparisonType.EQUAL, "SearchNumber", searchValue));
// add the exists-filter with a condition to the esq filter collection
var filters = esq.filters;
filters.add(Terrasoft.createExistsFilter("[AccountCommunication:Account:Id].Id", subFilters));
//receive the request value
esq.getEntityCollection(function(result) {
...
}, this);

As a result, the following request will be sent to the server:

SELECT Id, ... FROM Account
WHERE EXISTS 
(SELECT
[SubAccountCommunication].[Id] [Id]
FROM
[dbo].[AccountCommunication] [SubAccountCommunication] WITH(NOLOCK)
WHERE
[SubAccountCommunication].[AccountId] = [Account].[Id]
AND [SubAccountCommunication].[SearchNumber] = @P1
)

The @P1 parameter will store the searchValue value passed over to the filtering condition.

Like 1

Like

Share

0 comments
Show all comments