Lookup function

739 views
Skip to first unread message

Krish R

unread,
Oct 18, 2022, 2:12:35 AM10/18/22
to memento...@googlegroups.com
I have TWO TABLES - T1& T2

T1 has following 3 columns:
 1.  Code            - (integer)
 2.  Item Name - (text)
 3. Item Price    - ( integer )
This table is a reference table

T2 has following 3 columns :
1.  Code           - integer
 2. Item Name - calculation 
 3. Cost              - calculation
Above table  is a transaction table,  and is aggregated on Price 


On entering 'code' in column1 in above table, i would like 'item Name' and Cost to be auto-filled from the  data in T1. 

I have only about 100 items to deal with, and i know their codes by memory. Filling them from memory will be faster than selecting them through ' relationship'.

In excel, it is done through the 'vlook-up' function. 

Help please!
Krish

Craig Hunter

unread,
Oct 18, 2022, 8:42:24 AM10/18/22
to memento...@googlegroups.com, Krish R
Are you using Memento? To answer questions about Memento we prefer that the question uses Memento terms.

Are you trying to decide whether to use Memento? I bet we could have some answers for those kinds of questions too. We are Memento users, not Memento employees.

Your terms 'table', 'column', 'calculation', 'relationship' should be translated into Memento terms such as 'library', 'field', et cetera.

Excel formulas like vlook-up can often be implemented in Memento by a calculation field or by a javascript field. Two Memento Libraries can also be related by the Link-to-entry field.

I hope this helps
Craig

Bill Crews

unread,
Oct 18, 2022, 12:52:30 PM10/18/22
to Krish R, mementodatabase
The Lookup field IS the vlookup or hlookup field of Excel. To look up "in memory", you could hardcode the values in a script or maybe in a file and read them from the file. I hope the values don't change often, as you'll have to update things twice when you do.

Try the script itself.

--
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/CANbWJXjjpSMm6B9yrLyqiLBP8JT2o8ggCK1qTwb6dy-Q86bcwA%40mail.gmail.com.

Er Mo

unread,
Oct 18, 2022, 2:48:51 PM10/18/22
to mementodatabase
Hallo
Mit einen Trigger ( Eintrag erstellen / Vor den Speichern ) und eine 2 Bibliothek in der die Daten gespeichert sind muss es gehen . Das Skript liest das Code Feld und sucht in der 2 Bibliothek nach den dazugehörigrn Daten um damit die restlichen Felder aus zu füllen .

Hi
It has to work with a trigger (create entry/before saving) and a 2 library in which the data is stored. The script reads the code field and looks for the corresponding data in the 2 library in order to fill in the remaining fields.

Ernst

Bill Crews

unread,
Oct 18, 2022, 4:19:47 PM10/18/22
to Er Mo, mementodatabase
Yes, you could have a library upon Opening the library trigger that loops through library 2 and stores the values in a shared script. Then the library 1 trigger could access it from there. It could be in an Array or Map data strike in the shared script.

Er Mo

unread,
Oct 19, 2022, 1:05:30 PM10/19/22
to mementodatabase
Hallo Bill
Du bringst mich auf die Richtige Idee . Eine Schaltflächen Skript das die ID Zahl list und die restlichen Daten aus der 2 Bibliothek holt . So kann den User die Daten noch Überbrüfen vor sien  Gespeichert werden .

Hello Bill
You give me the right idea. A button script that gets the ID number list and the rest of the data from the 2 library. This allows the user to review the data before it is saved.

Ernst

Bill Crews

unread,
Oct 19, 2022, 1:26:03 PM10/19/22
to Er Mo, mementodatabase
I wish scripts could interact with the user, like throw up a card the user could fill in or at least push buttons on. Krish probably doesn't need it, but our other friend who wants to be able to restore previous values of an entry might want to let the user review the data before proceeding to restore the the values, but I know of no way to do that.


Krish R

unread,
Oct 26, 2022, 8:57:38 AM10/26/22
to mementodatabase
Thanks Craig. Apologies for not using Memento terminology. I have been using Memento for more than a year now and have created several libraries to keep track of my book collection/ music collection / to-do lists etc. I have so far used the functions already provided in the calculation fields to get things done. My difficulties usually arise with libraries having CODES to represent things - such as an inventory of different objects or the Dewey Decimal code for books etc. 

I want to hold the codes and object description in one library and reference it from the second library. I want to be able to enter the code ALONE in the second library and get the object description from the first library through a calculation field. This approach i thought would be ( for me  ) an advancement in my use of Memento, and the spark for that came to me from the vlookup function i had used many times in spreadsheets. But i found no such function readily available in the calculation field help of Memento.

I have no knowledge of JavaScript. But it was heartening to note in your reply that a calculation field can still be built. Can you  help .

Thanks,
Krish


Er Mo

unread,
Oct 26, 2022, 4:01:47 PM10/26/22
to mementodatabase
Hallo
Ein Skript für das Ausfüllen der fehlende Felder von einer 2 Bibliothek aus ist kein Problem . Für das Einbauen muss du einwenig Kentnisse haben / lernen . Kannst du ein Beispiel einstellen mit Daten wie die die du verwendest .

Hi
A script to fill in the missing fields from a 2 library is not a problem. For the installation you have to have / learn a little knowledge. Can you post an example with data like the one you are using.

Ernst

Craig Hunter

unread,
Oct 30, 2022, 1:09:58 AM10/30/22
to Krish R, mementodatabase
Thank you Krish, for your clear and well written reply. I had second thoughts after sending my first reply, worried that I had been offensive.

Javascript is much more powerful than calculation fields and the people who are active on this list prefer it. I dont expect a lot of users to vote for a vlookup function. For someone who is familiar with Exel and doesn't want to learn javascript, calculation fields are fine as long as they can do what you want. I agree, a vlookup function would be a great addition to the calculation field.

Your best option now is a javascript field that works like vlookup.

If you could convert table 1 to a string, you could implement what you want with the calculation field functions
indexOf(,,)
and
substring(,,)
If table 1 changes very rarely you could generate the string with
Import and export > Export to CSV
You would have to make sure that the fields of table 1 library were constant length. Pad text fields with trailing spaces.

-Craig

Er Mo

unread,
Oct 30, 2022, 3:36:12 AM10/30/22
to mementodatabase
Hallo
Habe mal die Lookup Funktion nachgebaut in einer Testbibliothek . Es gibt 4 Felder . 1 Code = hier wird der Code eingegeben und gesucht . Die Felder F1,F 2, F 3 , Hier werden die Daten von LETZTEN gefundenen Code eingetragen . Diese können Überschriben werden und somit beim Näcksten mal suchen werden diese Übernommen . In Feld Code den Code eingeben und auf die Schaltfläche drüken .
Hier noch das Skript für die Schaltfläche :

Hi
I once recreated the lookup function in a test library. There are 4 fields. 1 code = the code is entered and searched for here. The fields F1,F 2, F 3, Here the data of the LAST code found is entered. These can be overwritten and thus searched for the next time they are taken over. Enter the code in the Code field and press the button.
Here is the script for the button:

Ernst

var e= entry()
var cod = e.field("Code")
var bib = lib().entries();
var l = bib.length;
for (var j=0;j<l;j++){
var scod =bib[j].field("Code");
if (scod == cod && cod != null){
 e.set("F 1",bib[j].field("F 1"))
 e.set("F 2",bib[j].field("F 2"))
 e.set("F 3",bib[j].field("F 3"))
 cancel()
 exit()
}
}

Bill Crews

unread,
Oct 30, 2022, 4:39:22 AM10/30/22
to Er Mo, mementodatabase
While I grant that if a user is able & willing to develop triggers or actions, many things are possible, including distributing many values into many other libraries.

However, I think most of our forum members often just want to look up a value in another library, and they might be intimidated by the way Calculation scripts are arcane, abstruse, and cryptic and by the way JavaScript field scripts seem to be longish & involved.

But if a user just wants to do a simple vlookup in Memento, I think the introduction of the Lookup field in release 4.12.0 nails it. There's no need to learn & deal with MementoScript or JavaScript. You just identify the library name & field name, and Memento takes care of it for you. Credit should be given where credit is due as of release 4.12.0.

Now I think everyone who reads this forum knows that I favor and advocate using JavaScript in Memento when needed and possible, and with MJL (Memento JavaScript Library) enhancements in 4.13, you are beginning to be able to do much more in JavaScript than could be done previously, such as being able to obtain a list of the fields of a library, so you can process them in a general fashion, without having to know the way a library structure is defined. I could be wrong, but I don't think functionality has been added to Calculation fields (MementoScript) in over 5 years. JavaScript is the clear scripting direction for Memento. The new Button field supports only JavaScript.

For simple lookups, it is very easy to do a lookup in JavaScript. All you need to do is define the Link to Entry field to identify the other library and define a JavaScript field by providing the information in red below. The green part can be copied & pasted or memorized & retyped. The JavaScript vlookup of a field called Model Number using the Link to Entry field Product is this simple...

field("Product")[0].field("Model Number")

Since the Link to Entry field has the ability to define multiple links from a single entry (like when you have an order that refers to several products the customer purchased that day), there is the [0] construct that might make it look abstruse to some, but if you ever sell multiple products in an order, you'll appreciate being able to do that. For single links, it's always the same -- just [0]. I'll discuss this in a memento (my forum newsletter) very soon.


--
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.

Craig Hunter

unread,
Oct 30, 2022, 8:53:50 AM10/30/22
to Bill Crews, Er Mo, mementodatabase
The Lookup field in version 4.12.0 has no funtionality. Or maybe I don't understand how to use it. I use Memento on Android version 12.

The library with the lookup field also needs a link to entry field that links to the library that you want the lookup field to use. However the lookup field stays dead with no way to activate and with no error message.

Craig Hunter

unread,
Oct 30, 2022, 9:20:11 AM10/30/22
to Bill Crews, Er Mo, mementodatabase
I should have said the Lookup field in version 4.12.0 has no Useful funtionality. If you use the link to entry field to select an entry and then save the record you will see that the lookup field now shows the info that the link to entry field shows, but with cleaner formatting.

What we want is a field where you can type text which will be matched to a field in another library so that a record from that library can be selected. To link to the record "William" we want to be able to start typing W i l . . . and then the record William is linked. We do not want to have to open the other library and scroll down to the record "William" and choose it. We can already do that with the link to entry field, and as Krish pointed out, that is too slow.

I do not have time now to test the code that Ernst provided but it looks like a good start.
-Craig

Bill Crews

unread,
Nov 1, 2022, 1:48:42 AM11/1/22
to Craig Hunter, Er Mo, mementodatabase
If you use the link to entry field to select an entry and then save the record you will see that the lookup field now shows the info that the link to entry field shows, but with cleaner formatting.

Yes, just like the Calculation field or JavaScript field it is intended to replace for those who would rather not script. Actually, what you said is true if the lookup field is the entry name, but if it's another field, it displays that field's value just like the Calc or JS field would. So, goal achieved -- no scripting to get that value.

What we want is a field where you can type text which will be matched to a field in another library so that a record from that library can be selected. To link to the record "William" we want to be able to start typing W i l . . . and then the record William is linked. We do not want to have to open the other library and scroll down to the record "William" and choose it. We can already do that with the link to entry field, and as Krish pointed out, that is too slow.

Well "we" can want what we care to want, but I don't think you are in the target audience for the Lookup field. It doesn't do much, but unlike what you said, it's not useless. It fetches the value of any field in a linked library without scripting. That's useful to some.

What you say you want is exactly what Memento does when selecting a linked entry, but you object to the display of entries in the process. Fair enough. Libraries with a lot of entries and/or links take significant time to display the entries. To be clear though, it already works just as you want, but it displays the entries of the linked library before you start to type "W i l ...". That sounds like an idea for UserVoice -- an option when selecting a link to suppress the display of entries.

Craig Hunter

unread,
Nov 1, 2022, 11:58:13 AM11/1/22
to Bill Crews, Er Mo, mementodatabase
The lookup field doesn't look up anything. The link to entry field is doing the lookup. The lookup field is displaying the linked entry. That is the source of my frustration.

Here  are some examples where a lookup funtion would be used.
Postal codes. Enter the 5 digit Zip Code and the city, state is entered.
Part numbers for a manufacturer.
Stock keeping units (SKU) for a retailer.
Relating SKU to the UPC barcode number.

If you are on the phone, you want to do these lookups quickly. If you have the number you just want to enter the digits. It is faster than the process for selecting a linked entry.

I object to the slowness. But the display could be improved. Currently when you click on the magnifying glass icon (search) and start typing, there is a pop-up list of previous searches that contain the characters you typed. For a lookup function it would be more useful to have a pop-up list of field values that match the characters you typed. If the SKU is 8 digits and after you type a few, only a handful are possible, you don't have to keep typing all 8, just tap on the one from the pop-up list. If you make a typo, it is quickly clear because your desired number is not in the list. Currently you don't discover the typo until you type all 8 digits and activate the search.

If you are searching by name and you have the option of adding a record, you may find that multiple records have been added with alternate spellings. With a lookup function that shows possible matches as you type, this is much less likely.

I suspect that the lookup function I described cannot be implemented in javascript. It could be implemented as an option in the link-to-entry field.

-Craig

Bill Crews

unread,
Nov 1, 2022, 2:18:01 PM11/1/22
to Craig Hunter, Er Mo, mementodatabase
The lookup field doesn't look up anything. The link to entry field is doing the lookup. The lookup field is displaying the linked entry.

I don't want to be quibbling with you in the forum. You're one of the most knowledgeable and helpful people we have. But the fact is that the L2E field links from an entry in the current library to another library in the library structure. Linking to an entry of that library occurs when you add a link and choose an entry to link to. You can either pick from the list or tap the search icon to search for the entry. I understand that you'd rather not wait for the list or have to tap the search icon to start to identify the entry. That problem you have is with the L2E field. All the Lookup field does is look up the value of the designated field within the already-identified entry to fetch its value. It has nothing to do with identifying the entry.

If you are on the phone, you want to do these lookups quickly. If you have the number you just want to enter the digits. It is faster than the process for selecting a linked entry.

I understand your issue, but why blame the field that just fetches the value? All these years, you could have objected to the way the L2E field works, but you wait until there's a Lookup field and then object to it though it has nothing to do with identifying the entry. It just fetches. I don't understand why.

I object to the slowness. But the display could be improved. Currently when you click on the magnifying glass icon (search) and start typing, there is a pop-up list of previous searches that contain the characters you typed. For a lookup function it would be more useful to have a pop-up list of field values that match the characters you typed.

Ah, now we get to the real issue. I guess you'd like the developer to rename the Lookup field and call it something like Fetch and then provide a field called Lookup that works the way you want. I'd probably vote for that. Or maybe the name could be FindByField or something like that.

If you are searching by name and you have the option of adding a record, you may find that multiple records have been added with alternate spellings. With a lookup function that shows possible matches as you type, this is much less likely.

I think the Autocomplete option on a Text field works the way you're describing, not that helps you with lookups.

I suspect that the lookup function I described cannot be implemented in javascript. It could be implemented as an option in the link-to-entry field.

There is a family of find method on the Library object: find(), findById(), & findByKey(). Maybe one of them works the way you want, but I doubt it. find() matches all field values, findById() is totally something else, and findByKey works only with entry names. Yeah, FindByField or FindByFieldValue would be what you want.

Armin M

unread,
Dec 13, 2022, 4:14:36 PM12/13/22
to mementodatabase
I hope I can post a follow-up to this thread...

I'm evaluating Memento presently and one of my possibly usecases is the same as described above: Enter a code in library A via a reference from library B and then set other values in library A based on what else is defined in library B's row with that code.

Now I do understand the JS code above, in particular if (scod == cod && cod != null) - what I do not understand yet is how to trigger this code on an entry change (of the reference) in library A.

What I also don't understand is how to define this matching of A.scod to B.cod with a lookup function. That function gives me a "foreign" library selection, a field and a filter. I guess the filter is where I'd match the foreign (B) field to the value of the field in A - but how?

There is apparently no doc for that lookup function in https://wiki.mementodatabase.com/index.php?title=Main_Page ?

(sorry if I'm using wrong terms here, my Memento on Android is localized, apparently can't switch it to English ion order to get the right terminology...)

Bill Crews

unread,
Dec 14, 2022, 3:56:42 AM12/14/22
to Armin M, mementodatabase
Maybe you could explain what your doing a little bit?. "Enter a code in library A via a reference from library B" means very little to me.

Example, screenshot, something?

Armin M

unread,
Dec 14, 2022, 4:09:21 AM12/14/22
to mementodatabase
Thanks for getting back and sorry, I thought that was clear since I referred to the original example given here. So as an example:

Library A is a personnel table, library B is a table with zip codes and city name entries.
Library A has a field zip code which is a reference to the zip code field as defined library B, it also has a text field city name.
When choosing a zip code in library A, I'd like to set A's city name entry to the city name which is defined in library B for the chosen zip code in library A.

My take is that this can either be done by defining a trigger (I assume https://wiki.mementodatabase.com/index.php?title=Triggers#Updating_an_entry) on A's zip code entry and the JS code above - or (recommended?) by using a lookup function (which I don't quite understand for lack of documentation).

Bill Crews

unread,
Dec 14, 2022, 4:41:41 AM12/14/22
to Armin M, mementodatabase
3 ways to do lookups... The original way was to use Calculation field with '#{link.cityName}'. Then came the JavaScript field with field("link")[0].field("cityName"). Then came the Lookup field, which is trivial. Just pick Library B from the library list and then cityName from the field list.

If you want to store the city name separately in A (redundant with what's in B), you could then use a trigger in A (probably both Creating and Updating and After saving) with entry().set("cityName", entry().field("link")[0].field("cityName")). I don't recommend the trigger unless you have some overriding reason to replicate the stored data. The other 3 methods are just references to the data stored in B.

I use the JavaScript field because I use JavaScript a lot, but for most people, I think the Lookup field is the way to go.


Armin M

unread,
Dec 14, 2022, 9:01:16 AM12/14/22
to mementodatabase
I use the JavaScript field because I use JavaScript a lot, but for most people, I think the Lookup field is the way to go.

ok, I got it now. Installed the Desktop version which helped not having to do a 3-way translation of concepts, those I'm familiar with from SQL etc., the localized terms and the English terms in the docs etc. What also initially confused me is that Lookup depends ion a pre-existing relation (I assumed the rel was implicitly set with the lookup declaration) and that the relation only sets the target library, not a specific field in that library (thinking foreign key here...).

Anyway, lookup works now and I don't actually need to copy b/c CSV export includes the values for the referenced fields. Thanks for pushing me in the right direction.

The only thing I notice on Android is that the value for the looked-up field does not get displayed after having chosen the related entry, but only after save.

Bill Crews

unread,
Dec 14, 2022, 12:06:19 PM12/14/22
to Armin M, mementodatabase
The only thing I notice on Android is that the value for the looked-up field does not get displayed after having chosen the related entry, but only after save.

Interesting. After the save of what? The library A entry or the library B entry?

If the Lookup field doesn't work for you, the trigger might work instead. The trick would be to carefully select the trigger event & phase. Here are the choices...

Event typePhaseExecution modeObject / Method / Property
Opening a libraryOpening the librarysynchronousLibrary/lib
Opening an Entry Edit cardsynchronousDefaultEntry/entryDefault
Before saving the entrysynchronousEntry/entry
After saving the entryasynchronousEntry/entry
Opening an Entry Edit cardsynchronousEntry/entry
Before saving the entrysynchronousEntry/entry
After saving the entryasynchronousEntry/entry
Before saving the entrysynchronousEntry/link
After saving the entryasynchronousEntry/link
Before saving the entrysynchronousEntry/unlink
After saving the entryasynchronousEntry/unlink
Before deleting the entrysynchronousEntry/delete
After deleting the entryasynchronousEntry/delete
Before window displaysynchronousEntry/entry
After window displayasynchronousEntry/entry
Before addingsynchronousEntry/entry/property Favorites to True
After addingasynchronousEntry/entry/property Favorites to True
Before removingsynchronousEntry/entry/property Favorites to False
After removingasynchronousEntry/entry/property Favorites to False

You might try upon Opening an entry view card Before window display? That wouldn't involve a save.


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.

Armin M

unread,
Dec 14, 2022, 12:38:02 PM12/14/22
to mementodatabase
The only thing I notice on Android is that the value for the looked-up field does not get displayed after having chosen the related entry, but only after save.

Interesting. After the save of what? The library A entry or the library B entry?

(I clipped too short, re-opening that entry does then show the distance)

Performing the same interaction in the Desktop app renders the referenced field right away as expected - without having to save it first. Minor issue, though.

Craig Hunter

unread,
Dec 14, 2022, 2:33:40 PM12/14/22
to Bill Crews, Armin M, mementodatabase
I have also observed this. I have a library "Lib" with a link to entry field and two lookup fields. The link to entry field shows the name of the linked entry, and the lookup fields show two other fields in the linked entry. When I create a new entry in "Lib" and make a choice for the link to entry field, I want the lookup fields to show their fields from the linked entry, but they are blank. I have to tap on the checkmark to close the record, find the record in the list of records in library "Lib", and open the record. Then the lookup fields are filled in.

Bill Crews

unread,
Dec 14, 2022, 7:19:35 PM12/14/22
to Craig Hunter, Armin M, mementodatabase
Once again, interesting. Is this true also for the same lookup using a JavaScript field? I guess probably so.

Armin M

unread,
Dec 16, 2022, 5:17:19 AM12/16/22
to mementodatabase
Something else I noticed: Lookup fields are apparently not working with aggregates. e.g. I have a lookup with a number and would want those to be summed up in an aggregate for all rows/entries -> empty result for the aggregate.

I guess I'll give the JS approach a go...

Armin M

unread,
Dec 16, 2022, 6:36:29 AM12/16/22
to mementodatabase
So I played a bit with triggers and JS. While this basically works, I kind of miss an onchange event trigger...?

I have 3 triggers now: Creating an entry, updating an entry, linking an entry - all call a shared function at "Before saving the entry"

function setRefField() {
  entry().set("RefField", entry().field("RefID")[0].field("RefValue"))
}

Basically that works - but in terms of the proper values being displayed only *after* the entry is saved, in other words, the form for the entry is not refreshed as soon as the Lookup field is set or changed.

Also, from a developer experience POV, I sorely miss at least a JS console where I could observe when something triggers or do some log/tracing.

So, mixed feelings here...

Er Mo

unread,
Dec 16, 2022, 9:06:35 AM12/16/22
to mementodatabase
Hallo
 Es gibt ein Feld " Schaltfläche " bei den kann man ein Skript hinterlegen das Ausgefürt wird wenn die Schaltfläche gedrückt wird . Wenn du da dein Skript einfügst müsste sich die Anzeige auch ändern .

Hello
  There is a "Button" field where you can store a script that will be executed when the button is pressed. If you insert your script there, the display should also change.

Ernst

Craig Hunter

unread,
Dec 16, 2022, 9:51:52 AM12/16/22
to Armin M, mementodatabase
To have aggregates work with Lookup fields, do both of these: In Edit field for the numeric Lookup field choose an option under Aggregation (other than none). In Edit library / aggregation add your aggregation.

Bill Crews

unread,
Dec 16, 2022, 4:52:15 PM12/16/22
to Armin M, mementodatabase
I created a Link source library and a Link target library. I defined a Real field call numTarget in the Link target library initialed to 1. I aggregate with sum both the field and also the Lookup field in Link source. I have 1 entry in Link source and 2 in Link target.

For some reason, the sum in Link source is 4, but at least it's not 0, so it's not correct to say it's not working. The sum in Link target is 2, as it should be.

So, why is it 4 in Link source, and why did you say aggregating lookup field doesn't work? I don't know.

--
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.

Bill Crews

unread,
Dec 16, 2022, 4:58:35 PM12/16/22
to Armin M, mementodatabase
  | I kind of miss an onchange event trigger...?

So, what change event are you missing?

I have 3 triggers now: Creating an entry, updating an entry, linking an entry - all call a shared function at "Before saving the entry"

function setRefField() {
  entry().set("RefField", entry().field("RefID")[0].field("RefValue"))
}

Basically that works - but in terms of the proper values being displayed only *after* the entry is saved, in other words, the form for the entry is not refreshed as soon as the Lookup field is set or changed.

You might try setting Real-time scripts to make them run on any event, not just on save.

Also, from a developer experience POV, I sorely miss at least a JS console where I could observe when something triggers or do some log/tracing.

I sorely miss a console also. I sometimes construct my own kind of console using eval(), but it's not like having a read console as in Firefox.


Armin M schrieb am Freitag, 16. Dezember 2022 um 11:17:19 UTC+1:
Something else I noticed: Lookup fields are apparently not working with aggregates. e.g. I have a lookup with a number and would want those to be summed up in an aggregate for all rows/entries -> empty result for the aggregate.

I guess I'll give the JS approach a go...

bill....@gmail.com schrieb am Donnerstag, 15. Dezember 2022 um 01:19:35 UTC+1:
Once again, interesting. Is this true also for the same lookup using a JavaScript field? I guess probably so.

On Wed, Dec 14, 2022, 14:33 Craig Hunter <craigw...@gmail.com> wrote:
I have also observed this. I have a library "Lib" with a link to entry field and two lookup fields. The link to entry field shows the name of the linked entry, and the lookup fields show two other fields in the linked entry. When I create a new entry in "Lib" and make a choice for the link to entry field, I want the lookup fields to show their fields from the linked entry, but they are blank. I have to tap on the checkmark to close the record, find the record in the list of records in library "Lib", and open the record. Then the lookup fields are filled in.

--
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.

Armin M

unread,
Dec 17, 2022, 2:26:22 AM12/17/22
to mementodatabase
bill....@gmail.com schrieb am Freitag, 16. Dezember 2022 um 22:52:15 UTC+1:
I created a Link source library and a Link target library. I defined a Real field call numTarget in the Link target library initialed to 1. I aggregate with sum both the field and also the Lookup field in Link source. I have 1 entry in Link source and 2 in Link target.

For some reason, the sum in Link source is 4, but at least it's not 0, so it's not correct to say it's not working. The sum in Link target is 2, as it should be.

So, why is it 4 in Link source, and why did you say aggregating lookup field doesn't work? I don't know.

Originally, I had missed what Craig then mentioned: "In Edit field for the numeric Lookup field choose an option under Aggregation (other than none)"
-> problem solved

Armin M

unread,
Dec 17, 2022, 2:45:16 AM12/17/22
to mementodatabase
bill....@gmail.com schrieb am Freitag, 16. Dezember 2022 um 22:58:35 UTC+1:
  | I kind of miss an onchange event trigger...?

So, what change event are you missing?

on value change of given an entry, e.g. like https://www.w3schools.com/jsref/event_onchange.asp
 
You might try setting Real-time scripts to make them run on any event, not just on save.


But I guess I still don't get the event model here, https://wiki.mementodatabase.com/index.php/Triggers#Phases_3 says:

"Linking an entry This event starts when a user has added a linked entry (...) This event has two phases. In sequence: 1. Before saving the entry (synchronous) (...)  The script could be used to update some entry data based on other entry data, to keep it all coordinated."

In principle that is what I'm trying to do for Linking an entry / Before saving the entry.

But I think what happens is this: The event fires before the the linked entry value is saved and the JS function which relies on it ( entry().set("RefField", entry().field("RefID")[0].field("RefValue")) ) actually needs entry().field("RefID") to already be saved and not just set in the UI, hence it won't do anything at this time in the event loop.

If that's the case: Is there a JS way of getting the current value of an entry from the form itself (and not the backend)? Maybe that would solve the problem.

Bill Crews

unread,
Dec 17, 2022, 8:55:58 AM12/17/22
to Armin M, mementodatabase
You might try setting Real-time scripts to make them run on any event, not just on save.


Ok, but did you try setting real-time execution. I know how using triggers, but maybe JS fields, too? I'm just getting to come up with ideas here.

But I guess I still don't get the event model here, https://wiki.mementodatabase.com/index.php/Triggers#Phases_3 says:

If that's the case: Is there a JS way of getting the current value of an entry from the form itself (and not the backend)? Maybe that would solve the problem.

Yeah, I've been trying to figure the sequence of events in the creation of the problem, and I guess I get it now. You want to add or update a linked entry and before saving, access that new linked entry's field values in the source library. I've never tried that, but I'm not surprised, since as I understand it, the event model is based on values being available upon saving and not before. You might try an After saving phase. I think going much further with this will either be trial & error or will involve the developer himself.

When Vasiliy introduced bulk editing (I think it was then), his verbiage made me think he was moving from a form model to a field model -- basically, an event when a field in a card gets or loses focus or when the checkmark or Cancel is pressed. I was momentarily very happy and excited, and I told him so, which is when he calmed me down and clarified the narrow application of what he was enabling, which was nothing like what I was hoping for. If scripts could run upon focus changes and button pushes, Memento could become a full-fledged app builder based on a database, which would not at all be a bad thing. Of course, in that case, we'd need access to unsaved fields like what you're looking for. The question is when the Entry object is updated. I don't see why it shouldn't be dynamically. But it's not.

Er Mo

unread,
Dec 17, 2022, 2:16:41 PM12/17/22
to mementodatabase
Hallo
Wenn ein Wert von einer Verlinkten Bibliothek gebraucht wird , so kann man den mittels Skript holen . Man muss ihn aber selbee Suchen . Mit den Feldwert die ganze Bibliothek durchlaufen lassen .

Hello
When a value is needed from a linked library, it can be fetched using a script. But you have to look for it yourself. Use to loop through the entire library with the field value.

Ernst

Bill Crews

unread,
Dec 17, 2022, 3:05:18 PM12/17/22
to Er Mo, mementodatabase
This can also be done in an unlinked library, if you've granted permission to do so via the shield icon in the script editor.

--
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.
Reply all
Reply to author
Forward
0 new messages