Hi all! Ok I'm stumped. What are the column header...
# suitescript
k
Hi all! Ok I'm stumped. What are the column headers for custom segment value rows in SuiteScript?
I can get the values out with SuiteQL but it doesn't give me the column names
c
@Kris Wood How are you getting the values out with SuiteQL?
k
Copy code
const sql = 'SELECT * FROM customrecord_cseg_myproject';
const keys = ['owner', 'isinactive', 'scriptid', 'parent', 'recordid', 'lastmodified', 'created', 'name', 'externalid', 'id'];

let csegArr = [];

query.runSuiteQLPaged({ query: sql, pageSize: 10 }).iterator().each(page => {
  page.value.data.iterator().each(row => {
    csegArr.push(keys.reduce((acc, key, i) => {
      acc[key] = row.value.values[i];
      return acc;
    }, {}));
    return true;
  });
  return true;
});
There's probably a nicer way but I haven't found it yet
c
Are there columns aside from
'owner', 'isinactive', 'scriptid', 'parent', 'recordid', 'lastmodified', 'created', 'name', 'externalid', 'id'
that you're looking for?
How many values do you expect to return on a custom segment? Tens, hundreds, thousands?
k
no, I found them before you answered. 🙂
😄 1
thousands of rows
not my business requirements choice on that one. I'm just making it work
They want to upload a CSV of values for the segment, inactivate any existing ones that are not in the csv, add any net new ones from the CSV to the segment
so first I needed to get IDs and names from the existing values in the segment, and thus needed to know which column numbers they were in
c
Ah, I gotcha. I might do something like the following, but I bet what you have above works just fine!
Copy code
const sql = `
    SELECT 
        owner,
        isinactive,
        scriptid,
        parent,
        recordid,
        lastmodified,
        created,
        name,
        externalid,
        id
    FROM customrecord_cseg2
    `

    const results = [];

    query.runSuiteQLPaged({ query: sql, pageSize: 10 }).iterator().each(page => {
        results.push(...page.value.data.asMappedResults())
    });
k
that would work, too! I just didn't know the column headers when I started coding today so this is just where I ended up
c
I know how that goes for sure! Best of luck to you
k
Thanks!