Basic SuiteQL question I am selecting a field whi...
# suiteql
a
Basic SuiteQL question I am selecting a field which is a type checkbox. It returns as 'T' or 'F' but I want it to return as true or false. What function would I use in a query to accomplish that?
a
Copy code
query.runSuiteQL(theQuery).asMappedResults(x => {return {...x, fieldname: x.fieldname == "T"}})
a
Thanks. I appreciate the help, but I was looking for a suiteql function solution not a js solution
What I am trying to avoid is having to re-iterate over thousands of results
a
Even if millions of results the overhead will be minimal to run this map statement. Oracle databases don't have a boolean datatype. The only other thing I would suggest is to use something like
CASE WHEN fieldname = 'T' THEN 1 ELSE 0 END
then your
if(x.fieldname)
would work in js.
a
Got it. Thank you very much!
s
SQL has no boolean data type at all, and this is no different
a
Okay. I was coming from postgresql which does have boolean types. Thanks guys
a
Welcome to the clown database that is oracle.
s
generally 0, the empty string ‘’ or null all evaluate as falsy in JavaScript, so you can use that to your advantage.
Oracle databases tend to treat empty strings the same as null. Not sure if that holds true for SuiteQL, but I suspect it does (need to test it).
a
@Alan Fitch
Copy code
query.runSuiteQL(theQuery).asMappedResults(x => {return {...x, fieldname: x.fieldname == "T"}})
This doesn't work. I assume you meant this?
Copy code
query.runSuiteQL(theQuery).asMappedResults().map(x => {return {...x, fieldname: x.fieldname == "T"}})
a
Yeah typo.
👍 1
Only have slack on my phone.
a
Lol! I got excited there that there was a way to pass a callback to asMappedResults that I never knew about
🔜 1
p
@Azi: Use this SuiteQL function to return booleans:
BUILTIN_RESULT.TYPE_BOOLEAN()
😮 1
a
@Pavol Wow. Thank you this worked. Except it still leaves null results as null instead of false. But regardless it will still evaluate to falsy so that shouldn't be such a big deal