Search Contact by Different Role

Hi Creatio,

 

I am trying to filter a specific contact by using ESQ by having multiple roles as filters. How can I able to achieve that on ESQ when I want to filter on Roles?

 

Here is my code:

var esq1 = Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "SysUserInRole"
});
esq1.addColumn("SysRole.Name", "Role");
esq1.addColumn("SysUser.Contact.Id", "ContactId");
esq1.filters.add("RoleFilter1", esq1.createColumnFilterWithParameter(
	this.Terrasoft.ComparisonType.EQUAL, "SysRole.Name", "Role1"));
esq1.filters.add("RoleFilter2", esq1.createColumnFilterWithParameter(
	this.Terrasoft.ComparisonType.EQUAL, "SysRole.Name", "Role2"));
esq1.getEntityCollection(function(result) {
if (!result.success) {
	// For example, error processing/logging.
	this.showInformationDialog("Data query error");
	return;
}
var hasAQM = result.success && !result.collection.isEmpty();
 
if(hasAQM){
	this.set("HomartOpportunityAuthQuoteManager", result.collection.getByIndex(0).$ContactId)
}
 
}, this);

Thanks,

 

Like 0

Like

1 comments

Hello,

In your code you didn't set a logical operator for a filter:

esq1.filters.logicalOperation = Terrasoft.LogicalOperatorType.OR;

By default it's AND, due to that the system tries to find values that simultaneously have two roles in one record, but it's impossible.

For example, you have a user that has "Role 1" and "Role 2".

In the SysUserInRole table, this user will have two records, one with an identical SysUser value but a different SysRole. AND operation will not work in this situation. You need to use OR and in the result collection check the values that have the same SysUser.

Show all comments