New Feature: Access parameter values in getSchema

Dynamic sync tables use the getSchema function to generate the schema used by the table. Historically this function could only change the schema based on the dynamic URL and connected account, limiting the ability for the user to customize the schema.

We recently made a change that allows the getSchema function to access the parameter values the user has set on the table. The mechanism is the same as that used by the autcomplete function, if you’ve used that before.

Among other things, this makes it possible to add parameters for customizing the ID or display property of a table. For example, some data sources may not make it clear which column holds a good display value, but the user could decide after syncing down the data.

pack.addDynamicSyncTable({
  // ...
  getSchema: async function (context, _, parameters) {
    // Load the columns for the dynamic URL.
    let columns = getColumns(context);
    // Use the user-provided display column, or else fall back to the first column.
    let displayProperty = parameters.displayColumn || columns[0].name;
    // ...
  },
 // ...
  formula: {
    // ...
    parameters: [
      coda.makeParameter({
        type: coda.ParameterType.String,
        name: "displayColumn",
        description: "Which column's value to show within the chip for the row.",
        optional: true,
        // Auto-complete the column values the user can select from.
        autocomplete: async function (context, search) {
          let columns = getColumns(context);
          return coda.autocompleteSearchObjects(search, columns, "name", "name");
        },
      }),
    ],
    // ...
  }
});

Let us know if you have any questions or comments about this feature!

8 Likes

Oh, this is perfect for what we discussed on Wednesday! Bravo, Coda!

1 Like