Calculation field

97 views
Skip to first unread message

Francis Jauniau

unread,
Jul 31, 2025, 1:24:55 PM7/31/25
to mementodatabase
Hello,
I'm a newbie with Mementodatabase. A calculion field always return "Extression is invalid" ans I can't find the origin of this problem. Nesting of the "if" or other ? Could you help me ?
Here is my script whose purpose is to calculate the difference between two DATE fields that can be completed or not. "début de floraison" can also be bigger than "fin de floraison"
Thank you.

if(
    (#{début de floraison}==0) && (#{fin de floraison}==0),
    0,
    if(
        (#{début de floraison}>0) && (#{fin de floraison}==0)
        datediff(#{début de floraison}, now(),
        if(
            #{début de floraison}==0 && #{fin de floraison}>0,
            0,
            if(
                #{début de floraison}>0 && #{fin de floraison}>0 && #{fin de floraison} >= #{début de floraison},
                datediff(#{début de floraison}, #{fin de floraison}),
                if(
                    #{début de floraison}>0 && (#{fin de floraison}>0) && #{début de floraison} > #{fin de floraison},
                    datediff(#{début de floraison}, now()),
                    0)
                )
            )
        )
    )
)

Er Mo

unread,
Jul 31, 2025, 2:32:13 PM7/31/25
to mementodatabase
Hallo
Glaube das in einen " Berechnungsfeld " max 4 Verschachtelungen gehen . Versuche ein mit einen JS Feldtyp.

Hello
I think a calculation field can have a maximum of four nested elements. Try using a JS field type.

Ernst

Bill Crews

unread,
Jul 31, 2025, 4:48:00 PM7/31/25
to Francis Jauniau, mementodatabase
It was Calculation field scripts like these that made me quit using them many years ago now and switched to JavaScript fields and scripts. It's certainly more wordy than Calculation field scripts, but how cryptic can one tolerate? If you use indentation, as you did, and if you use braces, I think you'll find them much more comprehensible, and you won't run into quirks like the 4 levels thing. And it opens the door to triggers, actions, and the like.


--
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 visit https://groups.google.com/d/msgid/mementodatabase/557816b3-9834-4b40-9109-07bff33ab516n%40googlegroups.com.

Francis Jauniau

unread,
Aug 1, 2025, 2:51:45 AM8/1/25
to mementodatabase
Thank you for your answers. So I'm going to start JS at 80 years. I hope the free mobile version will allow me to do so for the sake of my orchids.

Mmm

unread,
Aug 1, 2025, 5:19:27 AM8/1/25
to mementodatabase
 Изучаем JavaScript:

1. Добавить поле JS.

2. Вставить код:

let start = field("début de floraison");

if (moment.isDate(start)) {

start = moment(start).startOf("d");

let fin = field("fin de floraison");

if (moment.isDate(fin)) {
  fin = moment(fin).startOf("d");
} else {
  fin = moment(Date.now()).startOf("d");
}

fin.diff(start, "d");

} else {
  0;
}

3. Нажать на "Добавить JavaScript библиотеки".

4. Включить библиотеку moment.min.js и подтвердить выбор.

5. Включить настройку поля "Выполнять в реальном времени".

6. Готово.

Шаблон с примером:
пятница, 1 августа 2025 г. в 09:51:45 UTC+3, francis...@gmail.com:
Reply all
Reply to author
Forward
0 new messages