Dropdown change on date

81 views
Skip to first unread message

Kenny Chu

unread,
Jan 18, 2023, 5:25:51 AM1/18/23
to mementodatabase
So I have a dropdown field with 2 value, completed and not completed and a date field. And the process will repeat each month. What I wanted to do is once I change the dropdown to completed and when the date I choose matches today's date then the dropdown will change to not completed. Is this possible?

Er Mo

unread,
Jan 18, 2023, 1:11:21 PM1/18/23
to mementodatabase
Hallo
Habe es mit der Übersetzung nicht ganz verstanden . Aber du willst deine Daten ändern lassen wenn 2 Bedingungen ( Datum und Auswahl bei einen Feld ) erfült sind . Dazu braucht du einen Trigger ( Erstellen eines Eintrags , Vor / Nach den Speichern ) mit den passenten Skript

Hi
Didn't quite understand the translation. But you want your data to be changed when 2 conditions ( date and selection in a field ) are met . For this you need a trigger (creating an entry, before / after saving) with the appropriate script

Ernst

Bill Crews

unread,
Jan 18, 2023, 1:34:44 PM1/18/23
to Er Mo, mementodatabase
It's easy to compare the drop-down to a value. The trick then is to compare the date to today. It's a trick in that if you don't completely strip off hours, minutes, seconds, and milliseconds, 2 dates though both today may compare as being different. The information on this page should help you do that. A Memento Date field has a value of a JavaScript Date object, and the getTime() method will get the current time in milliseconds. That's where you start stripping off the milliseconds...

The moment.min.js JavaScript library would probably be of help. The link for that is...

Keep in mind 24 hours in a day, 60 minutes in an hour, 60 seconds in a minute, and 1000 milliseconds in a second.

--
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/6e393924-77ca-433d-9a16-5c3a72bdbc85n%40googlegroups.com.

Kenny Chu

unread,
Jan 18, 2023, 5:21:49 PM1/18/23
to mementodatabase
ok. what if i wanted just get the date information?

Kenny Chu

unread,
Jan 18, 2023, 6:55:34 PM1/18/23
to mementodatabase
I got somewhere
var status = field("Task Status")
for (var i in status) {
if (moment().isSame(field("Task Date")))
status = 'Not Completed';
}
status;

However this only reflects when I change the dropdown and the JS will the change. How do I fix that?
Thanks,

Bill Crews

unread,
Jan 18, 2023, 9:06:41 PM1/18/23
to Kenny Chu, mementodatabase
var status = field("Task Status")
for (var i in status) {

If Task status is "drop-down", it's a Singly-Linked List, which is not an array, to be stepped through in a for loop, but rather a text field, which takes the value of one of the items defined for the field.

if (moment().isSame(field("Task Date")))

Need a 2nd argument indicating the granularity to be is same day.

status = 'Not Completed';
}
status;

So, let's try...

var status = field("Task Status");
if (moment().isSame(field("Task Date"), "day"))
    status = "Not Completed";
status;

What I'm not sure of is whether the Date object returned by field() is what isSame() is expecting. You might need...

if (moment().isSame(field("Task Date").getTime(), "day"))

I haven't used moment.js a lot.


Kenny Chu

unread,
Jan 19, 2023, 6:10:30 PM1/19/23
to mementodatabase
Worked perfectly Bill. However only the javascript field shows the result, the dropdown doesn't change it's values. 

Bill Crews

unread,
Jan 19, 2023, 9:05:22 PM1/19/23
to Kenny Chu, mementodatabase
The e.set("Status", "Paid in Full"); statement in the trigger script should change the value of the drop-down. JavaScript fields can affect only the value of the JavaScript field, not other fields. Use the trigger scripts (one for creates, one for updates).

Reply all
Reply to author
Forward
0 new messages