How to iterate through the values of another field in a Calculation field?

160 views
Skip to first unread message

Aayush Arya

unread,
Jun 13, 2020, 10:35:58 AM6/13/20
to mementodatabase
Hi.

I have a Products field in a Projects database that links to products in a Catalogue database, and it has the attribute Quantity.

I have a Total Price calculation field in the Projects entry that has the following formula:

#{product.price} * #{product:quantity}

The problem is that it only calculates the total price of the first linked entry in the Products field. Is there any way for me to go through all the linked products, multiply the price into quantity for each, and add all of them to the total? I know I can do it via JavaScript but then it does not allow me to specify a unit of measure, which is an important requirement here.

Ernst Moser

unread,
Jun 13, 2020, 11:59:41 AM6/13/20
to mementodatabase
Hallo

Du kannst die Summe jedes Eintrages in ein Feld schreiben lassen und dieses Feld in der Datenbank summieren.

Hi
You can have the sum of each entry written in a field and sum up that field in the database

Aayush Arya

unread,
Jun 16, 2020, 10:01:24 AM6/16/20
to mementodatabase
Thank you. That would not have worked for my purposes, so I ended up going with a JavaScript field instead.

Ernst Moser

unread,
Jun 16, 2020, 3:00:59 PM6/16/20
to mementodatabase
Hallo
Ja geht auch . Man kan das Feld ( Berechnung / JavaSkript) verstecken , so das der Nutzer sie nicht sieht .

Hi
Yes you can. You can hide the field (calculation / Java script) so that the user does not see it.

Aayush Arya

unread,
Jun 18, 2020, 11:44:28 AM6/18/20
to mementodatabase
How? It's a linked field, and the user is free to link as many products as they want. How do I go through each entry, multiplying the amount into the quantity? I'm not sure I understand your suggestion…

What I did was make a trigger script that fills a Total Price field that I've made read only for my users. It's not the most elegant solution but it works. It would be excellent if we could make fields invisible or read only for all users when setting up the database itself.

Ernst Moser

unread,
Jun 18, 2020, 2:32:12 PM6/18/20
to mementodatabase
Hallo
Man kann Felder Unsichtbar machen wenn sie von einem Auswahlfeld ( Feld A )abhängig sind. Wenn ich nun diesel Feld ( Feld A ) von einen 2 Feld ( Feld B ) abhängig mache . Feld A = Sichtbar von Feld B . Feld B = Sichtbar von Feld A . Sind beite Felder Unsichtbar kann ich dies NICHT Sichtbar machen , weil ich ja kein Feld Sehe . Um diese Sichtbar zu machen muss ich eine Wert in Feld B ändern . Das mache ich mit einen Skript . Hab dazu ein Beispiel.

Hi
You can make fields invisible if they depend on a selection field (field A). If I now make this field (field A) dependent on a 2 field (field B). Field A = Visible from field B. Field B = Visible from field A. If both fields are invisible, I CANNOT make this visible because I don't see any fields. To make this visible, I have to change a value in field B. I do that with a script. Have an example.

Gilles Mons

unread,
Jun 18, 2020, 2:44:02 PM6/18/20
to Ernst Moser, mementodatabase
If you want to hide a field from "Users" you can also do so in the database permissions, individually or by group ...

Personally I use it in a group, for access to a "Quote" database ...

Gilles Mons

--
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/0793867f-b301-4f3b-87d7-4b9575a6032fo%40googlegroups.com.

Gilles Mons

unread,
Jun 18, 2020, 2:44:18 PM6/18/20
to Ernst Moser, mementodatabase


Gilles Mons

Le jeu. 18 juin 2020 à 20:32, Ernst Moser <ernst...@gmail.com> a écrit :
--
Screenshot_20200618_203910_com.luckydroid.droidbase.jpg

Aayush Arya

unread,
Jun 19, 2020, 9:24:04 AM6/19/20
to mementodatabase
You’re right! The last time you gave me this idea, I did not quite understand what you meant, but it turns out it was very simple to implement. Thank you so much!

For the benefit of others reading this, here are all the steps needed to achieve what Ernst has suggested above:
  1. Add a Boolean checkbox field to the library called ‘Hide All’ with its default status as checked.
  2. Add another Boolean checkbox called ‘Hide Hide’ with its default status as checked.
  3. Add a dependency to both fields where it is only visible if the other one is unchecked.
  4. Now, whenever you want to hide a field from the user, add a dependency so it’s only visible when the ‘Hide All’ option is unchecked.
You can still change the value of hidden fields using scripts, but you cannot have them be the description, status or title of entries. If you want to make the value of a certain field the description, status or title of an entry without allowing the user (or, indeed, yourself) to edit it, create a calculation or JavaScript field that shows the value of that hidden field and use it for that purpose.

Now, if you ever want to see your hidden fields, you need to run the code “entry().set('Hide All', true)” from a script for all the fields in that library. You can create individual scripts in each library you have to do this, but I am outlining a better method below.
  1. Add a library and name it something appropriate (like ‘Configuration’ or ‘Settings’).
  2. Add a single choice drop down menu called ‘Library’ and allow yourself the ability to add items to it while editing. You can populate it with the exact names (including casing) of all your libraries where you are using the trick above.
  3. Add a Boolean checkbox called ‘Hidden Fields’ and set it to be checked by default.
  4. Save it and ensure that you do not share this library with your users (if any), unless you want to give them the ability to unhide your hidden fields.
  5. Add one entry each for all your libraries where you have hidden fields.
  6. Add a trigger script called “Update Settings” (or whatever) for the event “Updating an entry” and “After saving the entry”.
  7. In it, paste the following code and save it:
code.png

Now, whenever you want to show your hidden fields in any library to help you troubleshoot something, go into your Settings library and disable the Hidden Fields checkbox for the respective library. You can later build upon your Settings library by adding more configurable options for your libraries (like enabling/disabling notifications, etc.).

Once again, thank you, Ernst, for determinedly pointing me in the right direction.

Aayush Arya

unread,
Jun 19, 2020, 9:27:21 AM6/19/20
to mementodatabase
I missed on step: After adding the script, you need to give it permission to access all the libraries where you had hidden fields.

Ernst Moser

unread,
Jun 19, 2020, 10:31:38 AM6/19/20
to mementodatabase
Hallo
Gut wenn sie das mit den 2 Felder die sich gegenseiteg unsichtbar machen verstanden haben . Ich verwende dabei ein Feld namens " Stufe " in der Zahlen sind . So kann man unterschitliche bereiche ( Stufen ) freigeben . Die " Stufen Zahl "ist in einer Datenbank auf den Handy gespeichert und wird vor den Öffen der Ansichtskarte in das Feld " Stufe " übertragen . So hat der Benützer immer zugriff auf seinen Bereich , ohne was umzustellen .Wird die Datenbank mit den Unsichtbaren Felder über die Cloud syngronisirt , so wird IMMER die " Stufe " von der Datei auf den jeweilige Handy genommen . Bevor der Nutzer etwas Sieht wird das Feld schon Sichtbar / Unsichtbar .

Hi
Good if you understood that with the 2 fields that make each other invisible. I use a field called "Level" in which there are numbers. So you can release different areas (levels). The "number of stages" is stored in a database on the mobile phone and is transferred to the "stage" field before the postcard is opened. So the user always has access to his area without having to change anything. If the database with the invisible fields is synchronized via the cloud, the "level" is ALWAYS taken from the file to the respective cell phone. Before the user sees something, the field is already visible / invisible.

Bill Crews

unread,
Jun 19, 2020, 10:32:35 AM6/19/20
to Aayush Arya, mementodatabase
Thank you both for providing this information! I will find an appropriate place in the wiki for it. I love when people provide such things.

I do have one request though, when people do this in the future...

If you provide code to be pasted by the reader, provide the code in a form that can be readily copied. An image will not suffice.

In this case, I got around the problem by retyping the code. The script was not long, so it was not a big problem, but if it were long, I would be inclined to hunt for a free OCR app on Google Play to get the code copied. It's a habit best not learned. (I'm old. Maybe there's an easy way to do it nowadays that everyone but me knows about, but I doubt it.)

But again, the main point truly is: Thanks to the two of you for contributing a useful procedure that can be readily employed by forum members!

Ernst Moser

unread,
Jun 19, 2020, 10:44:41 AM6/19/20
to mementodatabase
Hallo
Habe eine Karte erstellt in der sich Jeder eintragen kann . So wissen wir wo sich der Andere aufhält . Sie könne sich die Karte herunter Laden .
In Menento 3Punkte Rechts -> Öffnen durch URL -> http://libs.mobil/ernst67/forumskarte eingeben -> zum Speicher die " Schwarzr Wolke" klicken .

Hi
I created a card in which everyone can register. So we know where the other is. You can download the map.
In Menento 3 points right -> Open by URL -> enter http: //libs.mobil/ernst67/forumskarte -> click the "Black Cloud" to save.


Am Freitag, 19. Juni 2020 15:27:21 UTC+2 schrieb Aayush Arya:

Aayush Arya

unread,
Jun 19, 2020, 11:07:13 AM6/19/20
to mementodatabase
I will do that in future, but I specifically used the image in this case because the code was short.

Also, FWIW, it does not apply to someone experienced like you, but I always prefer that newbies type the code from an image instead of copying and pasting it. Just helps you learn better.

But yeah, I’ll paste it in future.

Bill Crews

unread,
Jun 19, 2020, 12:00:46 PM6/19/20
to Aayush Arya, mementodatabase
Fair enough. I respond in this way not to respond just to you, but to others who I'm afraid will learn bad habits. So, we have similar instincts, but in different areas. I guess the ideal is for them to see both points of view, and we've done that. 🙂

Reply all
Reply to author
Forward
0 new messages