API call failing due to missing variables

Options

Hello,

I have a function that does the following actions from a high level:

  • Queries records from two tables
  • drills down into a specific field that links both tables [Table 1 ID (not xano) is primary and Table 2 has table 1's id (as secondary releationship)
  • Where the value in that field appears in both tables, add the xano id from the second table to the first table

I have tested this and it worked in principle.

However, there are records where Table 1's id won't appear in Table 2, and this is intentional. In these scenarios, I want the API call to skip them and move unto where Table 1's id appears in Table 2, and executes the xano id linkage. This doesn't appear to be the case as the API fails when that field is empty.

How do I go about this?

Tagged:

Answers

  • Max
    Max Member
    Options

    try doing it with try&catch. simply put all you have working as intended in try, and in catch put alternate function to solve records in loop that will fail.

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

    I see you're already familiar with conditionals in general, and that's the tool I'd use for this job. First ask if A has B, and if not, check if B has A. I'm not totally sure which line errored out on you (there are 2 get record statements in view) but that would be how I would compose the solution

    (I would be wary of this kind of bidirectional link in a data schema - it can make your db harder to manage in the medium term)

    Complicated data management is a big part of what we do in our daily office hours over at Statechange.