Help

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

1167 1
cancel
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
Stephen_Suen
Community Manager
Community Manager

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?

Example…

image

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

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

image

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

// Method 1
output.text(`${line1}\n${line2}\n${line3}`);

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


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.