array as input

Options

Hi all, I am in trouble using array as input in my stack.

In my case I have a "insured" table and a "policy" table. I am using filter by a custom query WHERE db:policy.id = var_2.id (var_2 is a list of policy id, resulting from customer relationship and auth control). I tried to pass this list and got this error

{

message:

ParseError: "policy.id" = [26,24], message=Lists are not supported.

}

but how to execute a search loop to each id until end of loop?

I have read question https://community.xano.com/discusion/1924451/how-to-use-an-array-of-objects-as-a-function-input but the answer is not clear for me.

help please :)

Best Answer

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Answer ✓
    Options

    Hey @thierry, based on your screenshot above, I would again recommend the IN operator. IN asks whether "A" is in ["A", "B", "C"]. So when the first argument is an int or a string, and the second argument is an array of same, you want to use IN.

Answers

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    You want to use the "IN" operator for this job. = will test whether "A" is "A". IN will test whether "A" is part of ["A", "B"].

  • thierry
    thierry Member
    Options

    IN operator will returns for selected value only. So, do you mean to add this inside a loop ?

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    If both are lists then you will want to use the OVERLAPS operator. IN is used to evaluate a single value "in" a list.

  • thierry
    thierry Member
    Options

    Hi Michael, thank you for this. Could you show us how to apply this ?

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    @thierry no problem, this is accessible in the by custom query section of query all records:

    You can also use CONTAINS to accomplish the same thing:


  • thierry
    thierry Member
    Options

    Hi Mickael, thank you for this tutorial. Easy to follow, but when I passing two existing id in my input list I stills get this error:

    {

    message:

    ParseError: "insured.id" contains [19,21], message=1st operand must be json or an array.

    }

    //19 and 21 are db table existing reference ids.

    // my "inputlist" is Type: integer and structure: list selected.

    I saw I have the integer [] in red alert ?

    any idea ?

  • thierry
    thierry Member
    edited December 2022
    Options

    Hi Ray, thank you to both of you It' s ok this way.

    OVERLAP returns the same Type error than with =

    message is: "Input requires integer. Currently set to integer[]."

    but with a IN operator I got the result I looking for.

    Have a nice day :)