Trying to get all columns when using mapped columns

I want to use mapped columns as there are a couple of key columns containing attachments that I don’t want to be lost if they are renamed, however I also need to read the rest of the columns as they will be displayed in a table layout. No matter what I try I only get the mapped columns, even when trying to use the column options:

const result = await grist.docApi.fetchSelectedRecord(1, {"includeColumns" : "full"});

Any ideas?

The plugin api is all over the place now. I have no idea why your code doesn’t work, as per the docs, it totally should, but whatever. Personally, I’ve taken to simply using grist.docApi.fetchTable(tableName) whenever I need to get something done. Though, stupidly, that function gives you a huge array in column format, so you need to convert it into something more sane. For example, like this:

GristUtil = {
  async fetchTableRecords (tableName) {
    let rawdata = await grist.docApi.fetchTable(tableName);
    let records = rawdata.id.map((id, rowIdx) => Object.fromEntries(Object.keys(rawdata).map((colName) => [colName, rawdata[colName][rowIdx]])));
    return records;
  },
  lookupOne (records, {...query}) {
    return records.find((record) => Object.entries(query).every(([colName, queryValue]) => record[colName] === queryValue));
  }
}

Usage:

  • Get all records of a table, with absolutely every last column included, by doing GristUtil.fetchTableRecords(yourTableNameHere)
  • Find a specific record from the list you just obtained using GristUtil.lookupOne(recordsListFromAboveGoesHere, {someColumnName: someValueToLookup, someOtherColumnName: someOtherValueToLookup})

Hope this helps!

(Also hope the devs get around to overhauling the catastrophic mess that is the plugin api at this point. :roll_eyes:)