Anyone know how to select all column names of a ta...
# suiteql
x
Anyone know how to select all column names of a table?
s
I think that would require access to system tables that I don't think are accessible to us via SuiteQL.
would love to be wrong about that
x
Argh. That makes things much harder, particularly when I have to check on a table that you can't readily make a saved search from (I don't think)
s
if you don't need to dynamically determine the column names you can just try a simple
select *
on that table
x
I'll have to double check later, but IIRC I think it presented the results of that as just a simple array with numerical indices instead of actual column names. To be continued.
asMappedResults() is my new friend.
s
yes, it's the slightly-less-capable analog to
nsSearchResult2obj()
🔌 1
😂 1
b
To get a list of all available column names:
Copy code
/**
 * @param {string} table
 * @return {string[]}
 */
const getAllColumnNames = table => Object.keys(query.runSuiteQL(`SELECT * FROM ${table} WHERE ROWNUM = 1`).asMappedResults()[0] ?? {}).sort();
To get all available columns for query results:
Copy code
SELECT * FROM table