Why does the following code produces [ ] instead o...
# suitescript
k
Why does the following code produces [] instead of [{"id": 12612}]?
Copy code
// Test tranid of 'SO0000073'
      var sql = `SELECT id FROM transaction WHERE tranid='${tranid}'`;

      var result = query.runSuiteQL({
        query: sql,
        params: []
      }).asMappedResults();
d
maybe a permission-related thing, depending on what user/role access the script is running in (seems fine to me otherwise though)
s
Are you passing tranid to the query? Your parameters option is an empty array
I usually find it easier to make up the sql statement using + to join variables together, then pass that statement to the runSuiteQL function
k
I passed the tranid into the params option and used + to combine variables.
Copy code
var result = query.runSuiteQL({
        query: 'SELECT id FROM transaction WHERE tranid = ?',
        params: [tranid]
      }).asMappedResults();
Expecting below after running the SQL statement:
Copy code
[
  {
    "id": 12612
  }
]
I'm receiving an empty object.
@dbarnett, I updated the permission for sales orders and that worked!
Thank you @dbarnett and @Sam L!