How to fix my loop (error invalid cast)

Options
Hi there! I'm trying to loop over another table using the inputs I get from the user to extract specific data.

See error:
[image.png]

My logic
1) For each loop - using coins array (user input)
2) Query records from another table (see screenshot) and return info that matches items in the loop + another id field.
[image.png]

Any help is appreciated!

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Hey  - is cryptoAlgos.coin an array or is it a scalar value? If so then you could use the IN operator:

    WHERE
    db: cryptoAlgos.coin IN var:item.path_name

    (You would also want to define the path name of your item variable as I see the input is an object array)

    Or if cryptoAlgos.coin is also an array you could use the new OVERLAPS operator
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Just saw your other post and that coins is an object array. You will need to first bind this field so that you have access to it's properties in the custom query section, for example in the By Joins section:


    [CleanShot 2021-12-06 at 17.50.01.png]
    this will give you access to the fields of that object in your custom query:

    [CleanShot 2021-12-06 at 17.51.22.png]
  • Alexander Thomsen
    Options
     I just realized one big mistake. coins in userStrategies should be a list. Based on a video I saw seemed I needed to use object! I changed it to text < list.

    so userStrategies coins is a list and CryptoAlgos coins is a single text field. So If I want to loop over userStrategies Coins and find the match in CryptoAlgos and add them as references to userStrategies cryptoalgos_id - should I make add. adjustments?

    Thanks! 
  • Alexander Thomsen
    Options
     would love your input when you have time been stuck for waay too long
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - I think I'm following, I made a loom. Hopefully I was on the same page:

    
  • Alexander Thomsen
    Options
     Thank you so much!!! Helped a ton and now I know a way to do it :)! Just one strange thing. I'm trying to do it whenever a user edit their specific record so I don't have to query the whole table every time.

    I followed your way but using the created record response and it throws an error. saying it can't find item.coins (which is strange because the var userstrategies contains the list). I would imagine I could also loop over the items in just one record
    [Screen Shot 2021-12-12 at 00.55.20.png][Screen Shot 2021-12-12 at 00.48.13.png]

    But when I do all records (like you showed) it works fine. 

    [image.png]
  • Alexander Thomsen
    Options
     or maybe I'm missing something about Xano logic 🙂
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    In your first example you are trying to loop through a single object. But really, it sounds like you want the array field of coins inside that single object. So you would loop through userStrategies.coins instead
  • Alexander Thomsen
    Options
    Thanks 😊!