Community
Showing results for 
Search instead for 
Do you mean 
Reply

GetCustomEntities Filter clause "AND" and "OR"

Bronze Super Contributor
Posts: 1,231
Country: USA

GetCustomEntities Filter clause "AND" and "OR"

 

Its Friday in the summer, brain not engaged. What am I doing wrong below?

 

 

This GetCustomEntities returns the correct record count:

Dim ArrayFilterCriteria As IFilterCriteria() = New IFilterCriteria(0) {}
ArrayFilterCriteria(0) = New ComparisonFilterCriteria(fielddescriptor, ComparisonFilterCriteria.Operation.Equals, "UPS")
me.entityList = Me.EntityManager.GetCustomEntities(Nothing, ArrayFilterCriteria)

 

 

This GetCustomEntities (with an OR)  returns no records. It should return more then the above example:

Dim ArrayFilterCriteria As IFilterCriteria() = New IFilterCriteria(2) {}
ArrayFilterCriteria(0) = New ComparisonFilterCriteria(fielddescriptor, ComparisonFilterCriteria.Operation.Equals, "UPS")
ArrayFilterCriteria(1) = New FilterClause(ArrayFilterCriteria, FilterClause.LogicalConnector.Or)
ArrayFilterCriteria(2) = New ComparisonFilterCriteria(fielddescriptor, ComparisonFilterCriteria.Operation.Equals, "FXF")
me.entityList = Me.EntityManager.GetCustomEntities(Nothing, ArrayFilterCriteria)

 

 

Thanks in advance.

-- JimDurkin

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: GetCustomEntities Filter clause "AND" and "OR"

For those that want t know I found the solution.

 

You need to type the field descriptor to System.ComponentModel.PropertyDescriptor. I was passing in the feidl descriptor as CustomEntityFieldDescriptor.

 

The fix for the code is:

 

Dim ArrayFilterCriteria As IFilterCriteria() = New IFilterCriteria(2) {}
ArrayFilterCriteria(0) = New ComparisonFilterCriteria(CType(fielddescriptor, System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "UPS")
ArrayFilterCriteria(1) = New FilterClause(ArrayFilterCriteria, FilterClause.LogicalConnector.Or)
ArrayFilterCriteria(2) = New ComparisonFilterCriteria(CType(fielddescriptor, System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "FXF")
me.entityList = Me.EntityManager.GetCustomEntities(Nothing, ArrayFilterCriteria)

Nickel Contributor
Posts: 175
Country: USA

Re: GetCustomEntities Filter clause "AND" and "OR"

It looks like System.ComponentModel.PropertyDescriptor is the absolute base class used for all of the FieldDescriptor objects. You may have been able to use the DBFieldDescriptor (w/ base class of PropertyDescriptor) or the MutableEntityFieldDescriptor (w/ base class of DBFieldDescriptor). It looks like CustomEntityFieldDescriptor inherits from MutableEntityFieldDescriptor. There is a nice chain, it's just a matter of figuring out which link in that chain starts working with the OR.
Tuned Listener
Posts: 44
Country: Canada

Re: GetCustomEntities Filter clause "AND" and "OR"

I followed your code exactly and I get this error when debugging, code works for 1 field but as soon as I ad the 'OR' and second field it fails. Any ideas why?

Capture.JPG

Nickel Contributor
Posts: 175
Country: USA

Re: GetCustomEntities Filter clause "AND" and "OR"

We're going to need to see the problem area of the code to know what's going on. It would also be beneficial if you could include a brief description of the program flow before and after the problem area. Sometimes the code in question is fine, but the implementation around it is the issue.
Tuned Listener
Posts: 44
Country: Canada

Re: GetCustomEntities Filter clause "AND" and "OR"

Sorry should have had more details, I just want to pull a list of all the custom entities that contain the status value of Active or Pending, it always fails on the last line marked below. Any help would be greatly appreciated.

 

Dim manager As CustomSubEntityManager(Of Act.Framework.CustomEntities.CustomSubEntity) = Me.actApplication.ActFramework.CustomEntities.GetSubEntityManager(Of Act.Framework.CustomEntities.CustomSubEntity)(entityName)

If manager IsNot Nothing Then

 

Dim ArrayFilterCriteria As IFilterCriteria() = New IFilterCriteria(2) {}
ArrayFilterCriteria(0) = New ComparisonFilterCriteria(CType(manager.GetCustomEntityFieldDescriptor("Status", Act.Framework.MutableEntities.FieldNameType.[Alias]), System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "Pending")
ArrayFilterCriteria(1) = New FilterClause(ArrayFilterCriteria, FilterClause.LogicalConnector.Or)
ArrayFilterCriteria(2) = New ComparisonFilterCriteria(CType(manager.GetCustomEntityFieldDescriptor("Status", Act.Framework.MutableEntities.FieldNameType.[Alias]), System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "Active")

 

               customSubEntities = manager.GetCustomEntities(Nothing, ArrayFilterCriteria)

*********FAILS ON THE LINE ABOVE

end if

Nickel Contributor
Posts: 175
Country: USA

Re: GetCustomEntities Filter clause "AND" and "OR"

Just a quick thought here. You are trying to get the CustomEntityFieldDescriptor each time. Are you certain it's returning what you expect? I'm wondering if you call that once and set it to an object, then use the object in the filter criteria statements, that could help out. Jim Durkin's example code is set up this way. If that does the trick, that makes me question what the GetCustomEntities call is doing with those filter criteria, such that you get a StackOverflow error.
Tuned Listener
Posts: 44
Country: Canada

Re: GetCustomEntities Filter clause "AND" and "OR"

Gave that a try using the code below, same error, in debug mode I can confirm the field descriptor object is returning the right field and has a value. So odd, any other ideas?

 

              Dim fielddescriptor As Object = manager.GetCustomEntityFieldDescriptor("Status", Act.Framework.MutableEntities.FieldNameType.[Alias])

 

                    Dim ArrayFilterCriteria As IFilterCriteria() = New IFilterCriteria(2) {}

                    ArrayFilterCriteria(0) = New ComparisonFilterCriteria(CType(fielddescriptor, System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "Closed")

                    ArrayFilterCriteria(1) = New FilterClause(ArrayFilterCriteria, FilterClause.LogicalConnector.Or)

                    ArrayFilterCriteria(2) = New ComparisonFilterCriteria(CType(fielddescriptor, System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "Active")

 

Nickel Contributor
Posts: 175
Country: USA

Re: GetCustomEntities Filter clause "AND" and "OR"

I had to look this one up in Object Browser. I had remembered some 3rd party api used an "End" clause, and it happens to be ACT. Not sure if this'll work, but worth a shot.

 

 Dim ArrayFilterCriteria As IFilterCriteria() = New IFilterCriteria(3) {}
ArrayFilterCriteria(0) = New ComparisonFilterCriteria(CType(fielddescriptor, System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "Closed")
 ArrayFilterCriteria(1) = New FilterClause(ArrayFilterCriteria, FilterClause.LogicalConnector.Or)
ArrayFilterCriteria(2) = New ComparisonFilterCriteria(CType(fielddescriptor, System.ComponentModel.PropertyDescriptor), ComparisonFilterCriteria.Operation.Equals, "Active")
 ArrayFilterCriteria(3) = New FilterClause(ArrayFilterCriteria, FilterClause.LogicalConnector.End)
Tuned Listener
Posts: 44
Country: Canada

Re: GetCustomEntities Filter clause "AND" and "OR"

I tried your suggestion and it says End is not a member of FilterClause.LogicalConnector, only lets me choose Or/And