Argh- Math function won't work on an integer

Options

I am reading an integer field and trying to add or subtract on it, and get the following error.

"Variable is not text. Are you referencing a full object?" I have confirmed that the field is an integer field in the database, and even tried using the "To_Int" function on the field before the math.

What am I doing wrong— this feels like a bust.

Answers

  • Xanoguy
    Xanoguy Member
    Options

    Holy cow, it appears the problem was that I was accessing the "vote" field from the object provided by a query.

    When I accessed that same field on the same object with the "get" function, the math operation succeeded.

    In other words, if I want to query a table for an entry, and upvote that entry, it appears I can't do that, because the math fails when accessing the integer fields of the object when pulled with a query.

    Is this the expect behavior. (see attached for the two ways I pulled the entry featurevote; the disabled one gave the error above).

  • Xanoguy
    Xanoguy Member
    Options

    Wow. Apparently it was this. Super non-obvious that the object I was returning was a list and not an object. Changed output of query to "single" instead of list. Hope to get the last 4 hours back at some point.

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

    by default query all records returns an array. Even when it returns one record/ it’s a list of one. Either you need to unwrap the array before your manipulation or change the return type to “single” (which makes it a more flexible version of get record- which I suspect is what you were going for!). Change the type by going to the output tab of query all records and clicking on the pencil next to the word “return”

  • Xanoguy
    Xanoguy Member
    Options

    Thanks Ray. That was it. You can imagine my confusion when I successfully could pull an integer field from the query result (e.g. "6") when the output was a list, but all operations with "6" failed. I changed the output type to single and am off to the races.

  • Xanoguy
    Xanoguy Member
    Options

    Now trying to figure out how to "unwrap" an array in a different context, but no joy in searching. (one allusion to unwrapping on statechange, but it was very specific).

    This looks like it'd come up a lot, but now that I have an array inside of a table entry, like in the video below, after some trial and error, I was able to return the data table containing the array, and then use dot notation to assign just the field containing the array to a new object, giving me a "single level" array like I wanted. Maybe this tidbit will save someone some time down the road.