Javascrpt field not work correctly sometimes

77 views
Skip to first unread message

David Acebes

unread,
May 19, 2025, 9:04:24 AM5/19/25
to mementodatabase
Hi, i have a library with a javascript field. In this field i want to see average of another field in dependency of type:

let res = 0;
let calc = 0;
let horas = field("Numero de Horas");
let tiles = field("Numero de Tiles por Pantalla");
let cantidad = field("Cantidad Material a Reparar");

if(field("Tipo")=='Tile' || field("Tipo")=='FC + Tiles'){
res = horas/cantidad
}

if(field("Tipo")=='Pantallas' || field("Tipo")=='FC + Pantallas'){
calc = tiles*cantidad;
res = horas/calc;
}

res = res.toFixed(2)+' h';

If field 'Tipo' is Pantallas the average value is 0 but another case, average is Ok.
Can anyone help me?

Er Mo

unread,
May 19, 2025, 2:25:23 PM5/19/25
to mementodatabase
Hallo
Vielleicht hast du einen Fehler in der Rechnung von

calc = tiles*cantidad;

Lass die mal diese Werte anzeigen

Hola
Quizás hayas encontrado un error en la factura de

calc = tiles*cantidad;

Déjenles mostrar estos valores

Ernst

David Acebes

unread,
May 19, 2025, 3:54:52 PM5/19/25
to mementodatabase
Sorry, i don't understand. Can explain more?

Er Mo

unread,
May 19, 2025, 4:06:36 PM5/19/25
to mementodatabase
Hallo
Beim JS Feld wird der Letzte Variable im Skript angezeigt . Also schreibet du als letzte Zeile mal
calc
Ist das auch 0 dann
tiles
und dann
cantidad
 Diese müsste der Inhalt von den Feldern " Numero de Tiles por Pantalla " und " Cantidad Material a Reparar " sein .

Hello
The JS field displays the last variable in the script. So, as the last line, you write
calc
If that's also 0, then
tiles
and then
cantidad
This should be the contents of the "Number of Tiles per Screen" and "Cantidad Material to Repair" fields.

Ernst

David Acebes

unread,
May 19, 2025, 4:21:12 PM5/19/25
to mementodatabase
Sorry but i can see where is the problem only if 'tipo' is 'Pantalla', in the same if, 'Pantalla + FC' is ok.
Can you put script with corrections?

David Acebes

unread,
May 20, 2025, 10:59:36 AM5/20/25
to mementodatabase
Finally solved with field type calculation but i want know why dont work on javascript field.
Thanks

Er Mo

unread,
May 20, 2025, 1:40:14 PM5/20/25
to mementodatabase
Hallo
Das Skript in einen JS Feld ist etwas ander und es gelten auch andere Regeln . Ein JS Feld ist auf den Eintrag gebunden . So kann es nicht auf eine anderen Eintrag zugreifen . Daher muss ich auch den Skript nicht sagen welche Eintrag gemeint ist .

Hello
The script in a JS field is slightly different, and different rules apply. A JS field is bound to the entry. Thus, it cannot access another entry. Therefore, I don't have to tell the script which entry it refers to.

Ernst
Reply all
Reply to author
Forward
0 new messages