Scripts: Current Date and Time with Button

Hello! First off loving Seatable. I have been searching for this unicorn of a software forever And am happy to have finally found it. After learning of the hard limits and extreme pricing of aircough cough table, I am currently evaluating the developer edition on Ubuntu server edition and all has been working well. I literally just cannot figure out a simple script to save my life.

My use case is when pressing a button, I trigger a script to display a confirmation dialogue asking if I am ready to begin setup? IF ā€œOKā€ is clicked the current date and time will be set into a column called ā€œStart Setup Timeā€. IF ā€œcancelā€ is clicked, the column is cleared. All works well, however the time automatically reverts to 00:00. Can any one help me with this? Thank you!

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

if (confirm(ā€œReady to begin setup?ā€)) {
let newdate = new Date();
var res = newdate.toLocaleString();
base.modifyRow(table, row, {ā€˜Setup Start Timeā€™ : res });
}

else {
base.modifyRow(table, row, {ā€˜Setup Start Timeā€™ : ā€œā€ });
}

ALSO follow up question, where in the world can I switch my settings to display in 12 hour format instead of 24 hour.

Thank you!!

LOVE SEATABLE

Hi, welcome to the SeaTable forum! And thanks for your kind words. Great to hear that you are enjoying SeaTable.

Which ā€œtimeā€ are you talking about here? Perhaps a screenshot could help us understand better.

Thanks for your response Attached is screen shot!
As you can see in the date column type the time is shown as 00:00 instead of the current time referenced from calling new Date ();
And in the script I know it is referencing a different column name then what is in a screen shot I just am on the move and asked an employee to screen grab a column. We have 4 identical scripts dropping into for columns ā€œStart setup time, end Setup time, start run time, end run timeā€. So functionality is the same.

Thanks for your effort and the screenshot. Now I understand.

I think your script is missing something: the new Date() will return a datetime with minutes bu it cannot be written correctly into a date cell yet. You need the base.utils.formatDateWithMinutes:

let date = new Date();
let formatDate = base.utils.formatDateWithMinutes(date);

And then use the formatDate to write into your date column. Try if this helps?

Details see the Utils - SeaTable Programming Manual

I upgraded my script to below:

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

if (confirm("Ready to begin setup?")) {
let date = new Date();
let formatDate = base.utils.formatDateWithMinutes(date);
base.modifyRow(table, row, {'Setup Start Time': formatDate });
} 

else {
  base.modifyRow(table, row, {ā€˜Setup Start Timeā€™ : ā€œā€ });
}

However, now nothing is placed into the column. To test things, I removed the else statement to allow for the record to be unchanged in event of cancel being pushed on the dialogue however this had no effect as nothing is still being placed into the cell. This is a head scratcherā€¦

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

if (confirm("Ready to begin setup?")) {
let date = new Date();
let formatDate = base.utils.formatDateWithMinutes(date);
base.modifyRow(table, row, {'Setup Start Time': formatDate });
} 

else {
  
}

You know what ā€¦ I typed your code into my table and it worked perfectly.

What Iā€™ve noticed in your code above, is that you donā€™t have indents in the if statement.
Of course the indents shouldnā€™t be the problem - but from this phenomena I assume, you might have copied and pasted your code somewhere else to SeaTable.

Thatā€™s the tricky thing: when pasting codes into SeaTable, sometimes some invisible formatting symbols are pasted in, too.

Would you try copying the following code and pasting into your table and see if it works now? Itā€™s directly copied from my table.

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

if (confirm("Ready to begin setup?")) {
  let date = new Date();
  let formatDate = base.utils.formatDateWithMinutes(date);
  base.modifyRow(table, row, {'Setup Start Time': formatDate});
}
else {
  
}

You are going to love thisā€¦ I copy and pasted your code in and still nothing happened.
THEN I HAD A THOUGHT.
I was working directly in safari and remembered javascript sometimes gets weird thereā€¦opened chrome and BOOM perfect! I knew it had to be something simple!!
Thank you so much for your help. I also just got my EE license and upgraded from the DE. I am presenting seatable to the principles of our screen printing company in just under 2 months. Provided all goes well we will requesting additional paid seats well beyond the 3 free. Great Great Great product and support!

1 Like

Great, I love to hear that!

That pasting issue is somewhat similar to an earlier incident with Mac OS but it was with Chrome, not Safari: Text I paste in a long text field is pasted as image - #7 by Karlheinz
(However, we recommend using SeaTable with Chrome)

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