jsdo filtering: nesting possible?

Posted by Peter Van Dyck on 29-May-2017 16:29

I searched for a while, but I found no posts in which this problem was handled. If I'm mistaken, please refer me to more info on the subject.

The main question here is; does the Progress jsdo support nesting in the filters of a read-call, as suggested by the Kendo dataSource filter documentation (without an example, though)? This other article also indicates that it's possible to nest filters, but yet again it doesn't provide an example.

I've been testing and working with the jsdo for a while now. I have a standard read module for a table called TypeDescription. It all works fine through the JSDO, I add this filter, for example, to assemble a set of records bound by a set of parent-ID's:

{ logic: "or", filters: Array[2] }

Where Array[2] is:

[{field: "ParentTypeDescrID", operator: "eq", value: 123}, {field: "ParentTypeDescrID", operator: "eq", value: 168}]

So here I'm selecting the children of 2 main items: 123 and 168. This returns the expected records.

But if I want to limit this to a subset with, for example, only the female elements, I would get a nested filter. The filter above would be contained by another filter with an "and" condition.

{ logic: "and", filters: Array[2] }

Where Array[2] is:

[{field: "Gender", operator: "eq", value: "female"}, { logic: "or", filters: Array[2] }]

The last part would be the original filter with the two parent-ID-objects.

If I try to run this nested filter through the "read"-method of the JSDO, it doesn't even try to call the PAS-instance, it just calls the ERROR-method with as parameter "null".

Has anybody else tried to use nested filters? Am I doing something wrong?

Here's the filter object sent to the read-method (it's the one from my actual call, filtering by language-ID, slightly different, but you get the point):

Posted by egarcia on 01-Jun-2017 04:40

Hello Peter,

Thank you for reporting this issue.

Did you find this issue working with Mobile / Telerik Platform or using the JSDO directly from Kendo UI?

Yes, the issue happens with JSDO version 4.3.1 but not with version 4.3.0.

This issue happens because when processing a nested filter, the field variable is not set.

The intention of the code is to replace the field name with its origName if serialize-name was used.

A simple fix is to change the following file in _convertToABLWhereString():

from

           if (tableRef._name) {

to

           if (field && tableRef._name) {

The code then would look like the following:

           if (field && tableRef._name) {

               // Use original field name instead of serialized name

               fieldInfo = tableRef._jsdo[tableRef._name]._fields[field.toLowerCase()];

               if (fieldInfo && fieldInfo.origName) {

                   field = fieldInfo.origName;

               }

           }

I have logged a bug report for this issue.

Thanks again,

Edsel

All Replies

Posted by egarcia on 30-May-2017 04:30

Hello,

Nested filters should work.

> If I try to run this nested filter through the "read"-method of the JSDO, it doesn't even try to call the PAS-instance,

> it just calls the ERROR-method with as parameter "null".

I do not see a particular issue with the filter expression that you mentioned. The one in the image has only one element for the "or" but that should be ok.

Some debugging would be needed in order to figure this out.

Are you calling the JSDO.fill()/read() method directly or are you using the Kendo UI DataSource?

Here are a couple of samples using nested filters:

oemobiledemo.progress.com/.../test001.html

oemobiledemo.progress.com/.../test014.html

I hope this helps.

Posted by Peter Van Dyck on 31-May-2017 16:53

I think I found why it's not working, and it appears to be... your foult, Edsel...

I'm using JSDO version 4.3.1, the ones in the example are using 4.3.0.

4.3.1 contains commit c972f88, committed on Nov 1, 2016 with as comment: Added Edsel's bug fix.

This commit contains the following code on line 379 of src/progress.util.js:

+            if (tableRef._name) {

+                // Use original field name instead of serialized name

+                fieldInfo = tableRef._jsdo[tableRef._name]._fields[field.toLowerCase()];

+                if (fieldInfo && fieldInfo.origName) {

+                    field = fieldInfo.origName;

+                }

+            }

Yet at this point, "field" can have an unknown value. The next line checks whether the current object contains a filters-property (in which case it won't contain a filter-property).

So the assignment of fieldInfo fails and crashes the procedure.

I'll move back to 4.3.0, I hope that'll fix my issue.

Posted by Peter Van Dyck on 31-May-2017 17:09

OK, tried it, 4.3.0 does the trick, 4.3.1 crashes.

On to 4.3.2, please ;)

Posted by egarcia on 01-Jun-2017 04:40

Hello Peter,

Thank you for reporting this issue.

Did you find this issue working with Mobile / Telerik Platform or using the JSDO directly from Kendo UI?

Yes, the issue happens with JSDO version 4.3.1 but not with version 4.3.0.

This issue happens because when processing a nested filter, the field variable is not set.

The intention of the code is to replace the field name with its origName if serialize-name was used.

A simple fix is to change the following file in _convertToABLWhereString():

from

           if (tableRef._name) {

to

           if (field && tableRef._name) {

The code then would look like the following:

           if (field && tableRef._name) {

               // Use original field name instead of serialized name

               fieldInfo = tableRef._jsdo[tableRef._name]._fields[field.toLowerCase()];

               if (fieldInfo && fieldInfo.origName) {

                   field = fieldInfo.origName;

               }

           }

I have logged a bug report for this issue.

Thanks again,

Edsel

Posted by Peter Van Dyck on 01-Jun-2017 14:36

Thanks, I'll adapt the code myself, for now, you're right.

I was using it with the JSDO from github in combination with Kendo datasources.

This thread is closed