Add 1 year from today


Hello,
can somebody please send me a tiny script that achieves following:
When you hit the green button the date should change to one year from today.
Thank you so much in advance!!

Hello,

You might be searching for something like this: (Replace Datum with your Date value name)

const table = base.getActiveTable();
const row = base.context.currentRow;
dates = row.Datum function addOneYear(date) {
  const dateCopy = new Date(date);

  dateCopy.setFullYear(dateCopy.getFullYear() + 1);

  return dateCopy;
}

const date = new Date(dates);

const newDate = addOneYear(date);
tdate = newDate.toISOString().split('T')[0]
base.modifyRow(table, row, {'Datum' : tdate });
1 Like

Hello!
Thank you very much for your reply.

Unfortunately I get this error message when I create a new script, paste the code and run the script:

File "index.py", line 1
const table = base.getActiveTable();
^
SyntaxError: invalid syntax

I’ve created a new table which looks like this (because I do not know what you mean with “Replace Datum with your Date value name”).

What do I need to change in the code?

Again, I thank you very very much for your help!

it is javascript not python, you need to add it as Javascript under scripts

When I add it as JS I get this error:

error: SyntaxError: Unexpected token ‘function’

Btw. you could also do this:

Create another column with the target date (Zieldatum) with the formula: dateAdd({Datum}, 1, 'year')

Then create a javascript script with the code

const table = base.context.currentTable;
const row = base.context.currentRow;
base.modifyRow(table, row, {'Ziel' : row['Zieldatum'] });

Now you can assign the javascript to the button and simply copy the value from “Zieldatum” to the column you’d like to have it in, for example into “Ziel”.

So it is not possible to change the existing date?
Thx!!!

It is because Ziel is not a fix date but just the copy of the calculated value. I’d hide the column Zieldatum in the final version of course.

In a few weeks, this will be a built-in option in the button column’s modify row action.

What will that be exactly?

Of course, you can change the existing date. Here is a video of the solution of AkDk7:
Every time you press the button, the date in the column date is increased by one year.
This is a very elegant solution that does not require an automation or python scripting.

year plus one

:star_struck:
that’s great news!!!

Thank you all very much for your help! It works fine now but I also look forward to a build in solution :wink:

1 Like

@FamilyBikes In SeaTable 4.1, which we released today, you don’t even need a script anymore. The “Modify row” button action now also supports dynamic date values (see below).

image