function works directly - but when called from another function it throws an error

Options
Orbiter
Orbiter Member
edited October 2023 in ? Help! I'm a Noob

Okay - I am beating my head against the wall with this one. I have a function that with two inputs that runs correctly. But when I run that function from within another function - with the exact same two input values - it throws an error. I made a loom video - appreciate anyone guidance.

https://www.loom.com/share/40370b5c55b44d38a8537aace75ac85e?sid=07f3f51f-9d60-4dfc-907f-5bdab5fc5c48

Comments

  • Louis Machado - CSA
    Louis Machado - CSA Administrator

    ADMIN

    Options

    Hello, there

    My guess is that this variable existing_master_email is not returning an integer, and then your conditional down below is passing through empty regardless of the conditional. Check your debugger to see what it is passing.

    If that is the case, try modifying the conditional using the expression below.

    Let me know if that points you in the right direction.

  • Orbiter
    Orbiter Member
    Options

    so the conditional expression is definitely NOT the issue as that works fine - although I prefer your expression. I put the debug log in the copyPerson function at the very top - set to the master_person_id

    when I run it - the debug logs show this:

    which implies to me that there is NO VALUE set for the master_person_id - when I change the value to "1" instead of the variable - it runs - and the "data" value shows the "1". But I have put in a stop & debug that 100% confirms the variable = 1. So … I'm totally dumbfounded.

  • Orbiter
    Orbiter Member
    Options

    I managed to hack my way to success by changing the query all records to get a record. I did also change my if / then expressions to what you suggested - although I when did that first and it did not work - but then I changed the query all records to get a record - it works now. I don't understand why … but I am happy anyway :)

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

    For others watching this thread - the issue was that the query all records was returning an array of "existing_master_email". Even though it only returned one record, it was still a "list". When using dot notation on the result to create lookup_id, one got [3] instead of 3. Passing that array to the field value of the get record call in the second function freaked it out, because it expected an integer (3) but got an array (3).

    This situation happens all the time. When we see a weird result like that, look for:

    1. square brackets near the value you're eyeballing. That could mean an array. If so, you might unwrap the array by fetching it's ".0" by dot notation: lookup_id.0.
    2. Using query_all_records to get a single record. This needs to be unwrapped, or edit on the "output" panel and mark it as "single" rather than "list" to prevent the wrapping in the first place.

  • Louis Machado - CSA
    Louis Machado - CSA Administrator

    ADMIN

    Options

    Awesome, thanks Ray!

    I knew this query was the culprit. 🙂