"Query all records" using text filters
Options
![David Richardson](https://us.v-cdn.net/6037124/user_avatars/2509231.jpg)
David Richardson
Member ✭
I have a form submission that I am using to extract specific records in a table. But first I first need to create an array of selected values from a form. I have a JavaScript function that does this just fine from the JSON submission.
data = { "Austin": "true", "cityScape": "false", "ranch": "false", "wildlife": "false", "abstract": "true", "cartoon": "false", "contemporary": "false", "cubist": "false", "dada": "false", "deco": "false", "digital": "false" .... };
var qParams = [];
for (var i in data) {
if (data[i] == "true") {
qParams.push([i]);
}
Output: [["Austin"],["abstract"],["acrylic"]]
I'm using the Xano function stack to achieve the same thing.
My function stack performs the "get entries" on the JSON to create an array of objects - name : value pairs which I access with dot notation.
{"entry":[{"key":"Austin","value":"true"},{"key":"watercolor","value":"false"}].....
Next the function stack loops through the key : value pairs creating variables: "thisValue" and "thisKey".
Then a conditional statement:
if [thisValue] = true;
then
add [thisKey] to the end of an array qParams[]
The conditional statement does not recognize the "true" value to extract ONLY those names where the value is "true". Instead EVERY key is added to qParams.
I'm not clear why this is happening in Xano. In some coding environments anything >0 is TRUE in Boolean. The == operator is not available in the Xano conditional statement so I'm not sure if this is a bug or a different workaround is appropriate.
data = { "Austin": "true", "cityScape": "false", "ranch": "false", "wildlife": "false", "abstract": "true", "cartoon": "false", "contemporary": "false", "cubist": "false", "dada": "false", "deco": "false", "digital": "false" .... };
var qParams = [];
for (var i in data) {
if (data[i] == "true") {
qParams.push([i]);
}
Output: [["Austin"],["abstract"],["acrylic"]]
I'm using the Xano function stack to achieve the same thing.
My function stack performs the "get entries" on the JSON to create an array of objects - name : value pairs which I access with dot notation.
{"entry":[{"key":"Austin","value":"true"},{"key":"watercolor","value":"false"}].....
Next the function stack loops through the key : value pairs creating variables: "thisValue" and "thisKey".
Then a conditional statement:
if [thisValue] = true;
then
add [thisKey] to the end of an array qParams[]
The conditional statement does not recognize the "true" value to extract ONLY those names where the value is "true". Instead EVERY key is added to qParams.
I'm not clear why this is happening in Xano. In some coding environments anything >0 is TRUE in Boolean. The == operator is not available in the Xano conditional statement so I'm not sure if this is a bug or a different workaround is appropriate.
Comments
-
You probably need to make sure that the "true" is of type text and not boolean. Otherwise, every string that has a value is considered a true-ish boolean.
There is an underlying issue of the use of true and false as strings - their more natural state is as booleans instead unless there are additional possible values. So you can handle it at either level in the stack, but you will want to make sure we handle them consistently - as booleans or as strings. -
Thanks and that was the fix. JSON is text therefore testing for = means the comparison needs to be with a text element.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback