"Query all records" using text filters

Options
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.

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    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.
  • David Richardson
    Options
     Thanks and that was the fix.  JSON is text therefore testing for = means the comparison needs to be with a text element.