Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

How do I align my output text if they're nested inside if statement?

Topic Labels: Scripting extentions
897 10
Showing results for 
Search instead for 
Did you mean: 

I’m training my JS muscle and have been playing around with the scripting block.
I’ve extended the currency conversion example, however I can’t figure out have to get my output text aligned when they’re nested?

Screenshot 2020-03-19 at 17.18.35

Anyone who knows if I’m doing something wrong?

10 Replies 10

This is actually a property of how whitespace is handled within template literals (strings that use the ` symbol). You can do one of the following:

  • Not indent the lines after the first line, e.g.
if (true) {
    output.text(`First line
Second line
Third line`);
  • Split it into multiple output.text calls, e.g.
if (true) {
    output.text('First line');
    output.text('Second line');
    output.text('Third line');

Have you thought about using the output.table() method?



You can also do some clever things with Markdown and tables.

Or do it all in one output.text() call.


let line1 = "Line one";
let line2 = "Line two";
let line3 = "Line three";

// Method 1

// Method 2
let multipleLines = [line1, line2, line3].reduce((total, current) => {
    return total + current + "\n";
}, "");

Hi @Bill.French thanks for the tip, do you know if there’s a way to not show the index number on the side?
Also do you know if it’s possible to make total under a few of the columns?

That also works like a charm. Thank you @kuovonne

Not that I am aware, but I have also looked for a way without success. @Stephen_Suen should comment on this.

Yes, it’s tricky, but all you have to do is add a new JSON item after all rows have been added that includes the sums of any specific columns.

The output.table() method is simply exposing the array of JSON item objects and this makes it possible to put also sorts content above, below, and even inside data rows. As such, it’s relatively easy to create aggregations, group-by’s, and averages, etc.

The world (of Airtable) is your oyster. :winking_face:

Currently, there’s no built-in way to exclude the index column when using output.table. We’d love to hear how you’re using this output method — are you typically passing in something like queryResult.records?

There are actually two vectors to this question - (i) hiding the index column, and (ii) use cases.

(i) I’d love to see a way to toggle the index column off, although, the current workaround is to generate a markdown table which is tedious, but useful.

(ii) I display records but more often than not, I’m using outbut.table() to render a grid of computational results like benchmarks, or aggregations, or text grids from other queries. Tables are one way to overcome the lack of UI formatting helpers.

I personally rarely use output.table() for queryResult.records.
I only ever output queryResult.records for debugging purposes, and for debugging, I don’t care if the index column appears or not.

I usually use output.table() for arrays of objects with keys of my own choosing based on the data I that I want to display. Usually, just before output.table(), I map the key names to more user-friendly names and omit any keys that I don’t want to display.