Cant pass numeric array as a dahboard filter via the JsAPI

Stephen Van Rooyen shared this problem 6 years ago
Resolved

Hi Guys,


One of our partners is trying to pass a numeric array as a dashboard filter via the JsAPI.

Passing a single numeric values works, but fails when trying to pass multiple numeric values. Works as expected for string and date value only happens when using numeric values.

Attached is an example.


Error : str.replace is not a function (cant do a replace for integer/numeric values)6e4a9605c628a1db4e4f497cc87b46cb


Regards,

Stephen

Best Answer
photo

Hi Stephen,
Thanks for reaching out with the issue you're facing.  I also experienced this behavior when using your code.
I continued my investigation, and found a manner in which to pass an array of integers that does work as expected.
By formatting the integer array as follows, I was able to successfully pass multiple integer values into the filter:

        function filterCallback(filters) {
                    var filterValues = {};
                    for (var i = 0; i < filters.length; i++) {
                        if (filters[i].description == 'Athlete ID') {
                           filterValues[filters[i].key] = ['11417', '9872'];
                         }
                    } 
Let me know if you find the same results. Thanks, Ryan

Replies (11)

photo
1

Hi Stephen,
Thanks for reaching out with the issue you're facing.  I also experienced this behavior when using your code.
I continued my investigation, and found a manner in which to pass an array of integers that does work as expected.
By formatting the integer array as follows, I was able to successfully pass multiple integer values into the filter:

        function filterCallback(filters) {
                    var filterValues = {};
                    for (var i = 0; i < filters.length; i++) {
                        if (filters[i].description == 'Athlete ID') {
                           filterValues[filters[i].key] = ['11417', '9872'];
                         }
                    } 
Let me know if you find the same results. Thanks, Ryan

photo
1

Hi Ryan,


It's works if i change the numeric values to text values.

Is this the intentended use? (i.e. should we always advise our customers to pass filter values as text)


Regards,

Stephen

photo
1

Hi Stephen,

It would appear that we expect an array of strings when passing multiple values. This is then converted as needed by our API depending on the filter requirements.

So in short, yes this is intended use and I would recommend advising this as standard practice to any of your clients.

Does this resolve your issue?

Thanks,

Ryan

photo
1

Hi Ryan,


In saying that you should probably get the wiki updated aswell, since what you are saying is contradicting the wiki.


As per the examples on the wiki numeric values are not sent as text values as seen below.

.b1d7d77504efa6f18acc77af3f15d7f0

Regards,

Stephen

photo
1

Hi Stephen,

Thanks for the reply. I believe this is actually valid, as the Wiki states that the format shown with an integer array is for a "between style" filter.

In the top box you've pictured, it's declared that when a "filter is a list style" you must pass the array as shown with strings.

Does that make sense?

Thanks,

Ryan

photo
1

Hi Ryan,


Even when the operand is set to between, it uses the same methods.

Which means that pass a numeric array for a between operand also will not work, because in the "back-end" its trying to do the same thing

(i.e trying to do a string replace on numerical values)


Regards,

Stephen

photo
1

Hi Stephen,

Thanks for the reply. I've tested this and confirmed that you are correct. I've also submitted a request to update our Wiki.

Is there anything else I can do for you today on this item?

Thanks,

Ryan

photo
1

Hi Ryan,

Thanks for the feedback, this does answer my query.


However in my opinion this should be treated as a bug or an enhancement request instead, and the fix is quite simple


All you have to do is bypass the string replace functions when the datatype is numeric

Below is a snippet from the JsApi, Dash.js file with the changes to bypass the string replace if the datatype is numeric :

5c933c51b74ad59e22ae3025822c3e36

With these 2 lines of code you can now pass the numeric array without having to convert it to text.


Regards,

Stephen

photo
1

Hi Stephen,

Thanks for the reply. Based on everything covered here, I will do the following.

Documentation states that a between filter should take an array of integers for starting and ending values. This is not working properly, henceforth I will raise this as a Defect. Since this Issue was originally created to address passing values into a numeric filter, I'll create this as a new public issue here.

The documentation does state that an in list filter expects an array of strings. Because of this, I will submit your request to allow an array of integers as an Idea for future enhancement. This is logged here for future reference.

I'm going to mark my reply on this post which resolved the issue as the best answer for future readers who may experience this problem. I will also close this since we've determined the resolution to passing the integers into the filter. Further tracking for each item can be done via the posts I've created under your name, linked above.

Thanks,

Ryan

photo
1

Thanx for this Ryan

photo
1

Hi Stephen,

Happy to help! Please don't hesitate to reach out with further questions or issues.

Thank you,

Ryan

Leave a Comment
 
Attach a file