Repost: Getting a specific field value with javascript

Argh! The topic closed - yet still unsolved:

Any help???

Hi, sorry that post was closed automatically.

And - to get the row “above”, there’s no simple way because the rows are not really sequenced in the database. The only identifier you can use is the row_id; but to get the current row’s previous row’s row_id doesn’t seem realistic.

What I would do is the following:

  1. Create a new column in the current view with numbering (could be an auto number column) and number the rows. So that you can always get the current row’s row number and minus 1 to get the previous row’s row number.
  2. With the previous row’s row number, you can get its row_id and get its content.

I hope this is clear!

thx for diving deep in my problem. can you help me how to get the value of a field, when I have const table and const row like in my code/art example?

When you have saved your table and row as const in your program, try using output.text(row) and click on Execute to print the row’s content on the console.

So you can see the data structure, and then you’ll know how to get the value of a field. It’s just basic programming then. Have fun!

thx … doesn’t work because the “auto number column” doesn’t resequence when changing how the rows are filtered or sorted. thx anyway … just one more question … I got the “output.text(row)” … so far so good … but one last thing:

… when there is code to CHANGE a field value … like

base.modifyRow(table, row, {‘Sendedatum’: formatDate});

isn’t there also code to READ a field value, like (imagined):

base.getRow(table, row, {‘Sendedatum’: formatDate});

Oh my god … I got it by trying … it’s simply like this:

const table = base.getActiveTable();
const row = base.context.currentRow;

thx anyway … I keep going!

Almost there! I can write the corrected dates to an alert:

However … in Chrome it won’t let me Copy Text from the alert. And in Safari it lets me copy the text but the insert in the multiple fields doesn’t work. Any ideas?

Other as in the screenshot, I also tried it with the dateformat adjusted to international format.

Happy to see you are learning JavaScript by yourself at last.

1 Like

Karlheinz, thank you so much for your time, effort and patience. I’m a little confused, what is all about plain vanilla javascript and what is SEATABLE specific. I’ll try not to bother you with mundane issues of coding.

Nevertheless … anybody knows, why my copy and paste solution doesn’t work?

You are welcome! I was testing the new version in the past days, and now I have finally got some time to write an example for you.

Let’s say, in this table, we have these columns:

And with the button “Get result”, you would like to get the Value from the previous row, add 7 to it, and write it in the Result of the current row, is that right?

The thought behind this is simple: With a script, you

  1. first read all the rows and save them in an array rows.
  2. Then you can check each element in rows and compare its _id with the current row’s _id.
  3. If it matches, then get the previous element’s Value and
  4. add 7 to it, and write it in the current row’s Result.

Along this thought, I’ve written the following example script:

const rows = base.getRows("Table10", "Default View");
const currentRow = base.context.currentRow;

for (let i=0; i<rows.length; i++) {
  if (rows[i]._id === currentRow._id) {
    base.modifyRow("Table10", currentRow, {"Result":rows[i-1].Value+7});

I hope this example helps you further. It works perfect in my table (Of course there’s no result with the first row):


Whoa!!! I LOVE YOU!!! It works!!! Thank you sooooo much!


const table = base.getActiveTable();
const row = base.context.currentRow;
const rows = base.getRows(“Table10”, “Default View”);
const currentRow = base.context.currentRow;

for (let i=0; i<rows.length; i++) {
if (rows[i]._id === currentRow._id) {

datecalc = rows[i-1].Value;
datecalc = Date.parse(datecalc);
datecalc = datecalc+(7*86400000);
formatDate = base.utils.formatDate(datecalc);
base.modifyRow(table, row, {'Value': formatDate});


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.