Button to actualize to current date

Visto 72 veces
Saltar al primer mensaje no leído

Filipe Noronha

no leída,
3 may 2023, 10:22:483/5/23
a mementodatabase
Hi,

I am trying to create a button that automatically updates a Date field, to the current day. So every time I open a entry I can track the last time I interacted with that entry.

I understand nothing of coding so I tried to use Chat GPT to help me.

It gives me this code:
// Get the current date var currentDate = new Date(); // Get the field by its ID var field = Fields.fieldById("your-date-field-id"); // Set the value of the field to the current date field.setValue(currentDate);

and it tells me to substitute "your-date-field-id" to my actal field ID. The name I gave to the field is "Last Interaction" but this doesn't seem to be the ID.

Can anybody help me in how I can do this?

Bill Crews

no leída,
3 may 2023, 12:03:593/5/23
a Filipe Noronha,mementodatabase
I wish good luck to all those who want to solve their problems without their participation by using ChatGPT or similar AI code generation tools. As I've said before, I personally am not interested in using my own added participation to make these things work. People could make work for me every time they decide to type in a query and send the forum a message.

Still, I'm interested in the problems users want to be solved, and if I can help, as always, I'll do so. In this case, ChatGPT got 1 of the 3 statements it generated more of less correct, though that's only part of the solution.

A trigger can help in this, but a JavaScript field should probably be enough. When you add the JavaScript field, note the following option: Execute script in real time. Here's what the wiki says about this option...

A script can be executed both when an entry is created or changed and when it is displayed.

The time of script execution is set by the toggle button Execute script real time on the field edit screen. It is reasonable to enable this option if your script contains functions that depend on the current time. Online execution in case of a large number of entries can significantly increase the time required to open the library.Turn this option on.

I believe this will give you what you want if the script you use is...

new Date();


--
You received this message because you are subscribed to the Google Groups "mementodatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/9a0cda42-f796-470a-b0f7-64930037180an%40googlegroups.com.

Bill Crews

no leída,
3 may 2023, 19:55:023/5/23
a Filipe Noronha,mementodatabase
Upon rereading, I could add 2 things. First, my suggestion does not include a button. If you really want a button, you should decide if you want to push it ebay time you touch an entry or whenever you open a library. The former could be either an entry action or a Button field. The latter could be a library action, but in that case, the action would probably set the time & data of every entry to the same current time, which is likely not what you want.

The entry action is simple. It requires a Date field instead of a JavaScript field, action set as an entry action, and the following script...

entry().set("dateFieldName", Date.getTime();

If you use the JavaScript field, the script should be slightly different than what I said before...

Date.getTime();

Filipe Noronha

no leída,
5 may 2023, 18:31:305/5/23
a mementodatabase
Hi,

thank you for your help.

I didn't achieve what I want already. But your answer was the starting point of me wanting to learn more by my own in order to get the things I want done. Have a nephew that work on coding and he recomended me some videos to start. I realize it is going to be a long journey.

Thank you.

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos