Trigger: Updating a field (new Event in triggers v4.9.1)

748 views
Skip to first unread message

Pedro Mapo

unread,
Oct 29, 2020, 7:08:03 AM10/29/20
to mementodatabase
Could someone explain me, with a simple example. How does the new trigger event works?
Thanks.

Bill Crews

unread,
Oct 29, 2020, 9:42:49 AM10/29/20
to Pedro Mapo, mementodatabase
The first info we all got was:

A new event type for the triggers has been added to execute scripts after changing fields in a table - "Updating a field". In addition, this event is executed after change a field directly from the list of entries.   
The global function field() allows receiving the edited field. This function returns a Field object, that has the next properties:
field().title - The name of the edited field.
field().value - Get the value of the edited field.
Also, It is possible to change the value of the edited field:
field().value = 'newValue'
__________

On Oct 21, I received this from Vasiliy to correct a misunderstanding I had -- that this applied not only to changes in the list, but also to fields during edit. Nope-- only in the list. A smaller feature benefit.

In the Desktop version, it is called when the fields in the table are changed or when you change fields from the list, for example - choice fields or checkbox can be edited directly from the list.
So, for Android the same, this event executed when you edit fields directly from the list, or kanban (move entries in another column is changing one field).  Android doesn't have the ability to edit fields from the table, but it will be implemented in the future.
The main purpose of this event - catch changing fields outside of the editing entry screen. 
Unfortunately, this event is not triggered when changing a field in several records at the same time. It might make sense to add this.

This event has access to a global function field(), that allows receiving the edited field. This function returns a Field object, that has the next properties:
field().title - The name of the edited field.
field().value - Get the value of the edited field.
It is possible to change the value of the edited field:
field().value = 'newValue'

It is possible to call the "cancel()" function in the Before Save phase to rollback changes.
__________

My personal view is that I need to be aware of all changes to the field...period. I'm either catching all changes or I'm not. Not only sometimes & not others. That applies to both adding support for multiple-entry edit from list and to field-by-field edit from the edit card. Still, it is a useful piece to have added for others, just got for me, so enjoy.
__________

A user noted that there is no field().oldValue. Amundsf provided a workaround to that.

On Thu, Oct 29, 2020, 07:08 Pedro Mapo <pedr...@gmail.com> wrote:
Could someone explain me, with a simple example. How does the new trigger event works?
Thanks.

--
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/a8481234-0962-427d-a125-5b2c7cf80295o%40googlegroups.com.

Bill Crews

unread,
Oct 29, 2020, 9:45:05 AM10/29/20
to Pedro Mapo, mementodatabase
I will be adding wiki update for the latest changes soon. I need to finish testing them. This is a part-time job for me.

Bill Crews

unread,
Oct 29, 2020, 9:53:28 AM10/29/20
to Pedro Mapo, mementodatabase
Oh! And one more message I got from him...

This event is the same as in the Desktop 1.5.0 beta version: https://groups.google.com/g/mementodatabase/c/OVO34t-JZ2Q

| I got it.

In the Desktop version, it is called when the fields in the table are changed or when you change fields from the list, for example - choice fields or checkbox can be edited directly from the list.

So, for Android the same, this event executed when you edit fields directly from the list, or kanban (move entries in another column is changing one field).  Android doesn't have the ability to edit fields from the table, but it will be implemented in the future.

That's all I have, so far. I've tested tags. I'm working on lists now. I'll get to field change from list soon, and I'll post then to the forum & update the wiki.


On Thu, Oct 29, 2020, 09:42 Bill Crews <bill....@gmail.com> wrote:

Bill Crews

unread,
Oct 30, 2020, 6:03:41 AM10/30/20
to Pedro Mapo, mementodatabase
I finally started testing the field update trigger.
Set up trigger as Updating a field / After saving the entry.
Used script:

var f = field();
message("|" + f.title + "| = |" + f.value);

Added a checkbox field to a library and set Where you can edit to all 3 places. I haven't checked Table view yet. I'm not sure if that's supposed to work yet on mobile, though it certainly should on desktop.

When I tested in the script editor, field() returns null. I had expected it to prompt me with a list of entries, so I could pick one to test with. I don't know when to expect the prompt and when it'll just result in words.

After going back to the entries list and checking an entry's checkbox, it properly emitted the expected 3-second message at the bottom of the screen.

I didn't try multi-selecting entries and checking their checkboxes, but according to Vasiliy, the trigger should not fire.

Note that it lets both multi-selected entry updates and edit card entry updates go untriggered. I expect him to provide us the multi-select trigger in a future release -- maybe soon? The edit card field-by-field update trigger is (I'm guessing) far harder to implement -- though also far more beneficial to the user -- so if he implements that, it I don't expect it soon. So, it'll be a while before we can have all updates under our scripting control.

I'll continue to test various scenarios and let you know of any wisdom I might obtain. I haven't tested other choice fields yet --single & multiple choice list fields and radio buttons and checkboxes fields. I believe it is supposed to work on them as well.

Taeke

unread,
Nov 2, 2020, 9:22:57 AM11/2/20
to mementodatabase
Could you point us to the workaround for oldValue you mention in this post?

Op donderdag 29 oktober 2020 om 14:45:05 UTC+1 schreef bill....@gmail.com:

Bill Crews

unread,
Nov 2, 2020, 11:25:59 AM11/2/20
to Taeke, mementodatabase
It was from Amundsf, shortly after the initial message. I'll forward it to you next...

Bill Crews

unread,
Nov 2, 2020, 11:54:59 AM11/2/20
to mementodatabase
The workaround...

Sebastian Amigon

unread,
Dec 2, 2020, 9:27:46 AM12/2/20
to mementodatabase
why memento tells me "cannot read property title from null"?

Bill Crews

unread,
Dec 2, 2020, 10:35:56 AM12/2/20
to Sebastian Amigon, mementodatabase
It means you think you have an object in your variable, but either you don't or that variable has become set to null. This often occurs if a method or function to supposed to return an object, but it has an error, so it returns null. If you don't check for null in these cases, you get the error message you describe.

Beth Dixon

unread,
Dec 2, 2020, 10:43:35 AM12/2/20
to Sebastian Amigon, mementodatabase
Hi there, can you please supply your code to the forum so we can review for issues.

Thanks,

Beth

Sebastian Amigon

unread,
Dec 4, 2020, 11:05:17 AM12/4/20
to mementodatabase
How do I check if it's null?

Er Mo

unread,
Dec 4, 2020, 12:09:05 PM12/4/20
to mementodatabase
Hallo
" null" ist nicht gleich " 0 " . " null " bedeutet das nichts da ist . . Ich definire einen Variable ( A )  und weiße ihn keinen Wert zu . So hat der Variable( A ) der Wert " null" . Egal ob da jetzt eine Zahl sein sollte oder ein Text , Datum . Erst wenn ich A = 0 sage hat der Variable ( A ) den Wert " 0 "

Hello
"null" is not equal to "0". "null" means that nothing is there. . I define a variable (A) and give it no value. So the variable (A) has the value "null". No matter if there should be a number or a text, date. Only when I say A = 0 does the variable (A) have the value "0"

Sebastian Amigon

unread,
Dec 4, 2020, 12:40:10 PM12/4/20
to mementodatabase
but I'm entering data, I don't know why the trigger is not executed

Er Mo

unread,
Dec 4, 2020, 2:20:13 PM12/4/20
to mementodatabase
Hallo
Hast du den Trigger mit einem anderen Auslöser getestet ?
Ich lasse dazu einen Text ausgeben
message (" Text ")

Hello
Did you test the trigger with a different trigger?
I have a text output for this
message ("Text")

Sebastian Amigon

unread,
Dec 4, 2020, 2:34:53 PM12/4/20
to mementodatabase
I'm using updating a field, I don't know if the field() function works with other events

Er Mo

unread,
Dec 4, 2020, 2:53:29 PM12/4/20
to mementodatabase
Hallo
Ja . entry().field("   ") geht bei allen außer es gibt noch keinen Eintrag . (Beim Erstellen / vor den Speichern) . Sonst erkläre mir was du genau vorhast . Was du bewirken willst .


Hello
Yes . entry (). field ("") works for all unless there is no entry. (When creating / before saving). Otherwise explain to me what exactly you are up to. What you want to do.

Sebastian Amigon

unread,
Dec 4, 2020, 5:47:46 PM12/4/20
to mementodatabase
what they are explaining here, how the global field () function works and its .title and .value properties. But the trigger gives me an error when I'm testing or updating a field

Bill Crews

unread,
Dec 5, 2020, 3:16:39 AM12/5/20
to Sebastian Amigon, mementodatabase
Is there a reason why you haven't supplied your trigger code? A screenshot of the error message and of the library edit screen would also be helpful if you attached them. It seems to me we are, as we say in America, shooting blind (trying to help with insufficient info).

Sebastian Amigon

unread,
Dec 7, 2020, 10:11:34 AM12/7/20
to mementodatabase

Sebastian Amigon

unread,
Dec 7, 2020, 10:13:36 AM12/7/20
to mementodatabase
El sábado, 5 de diciembre de 2020 a las 2:16:39 UTC-6, bill....@gmail.com escribió:
imagen_2020-12-07_091327.png

Bill Crews

unread,
Dec 7, 2020, 11:28:02 AM12/7/20
to Sebastian Amigon, mementodatabase
In this case, it is apparently a JS field, and the first statement calls field() unfortunately just like that, with no arguments. field() requires one argument, a string with the value of the name of the field to fetch the value of. You have given it no argument. I'm not sure, because I've never done it, but I strongly expect it turns null on this case. Since you don't check the value returned, when you reference the return value in campo (nun right now) to get the title (name) of the object. It tries to get the title of null and displays an error.

Either that, or it's smart enough to see that it will do that and not even execute the script.

Then there's the question as to whether a Field object has title as a property. Maybe not, as we've never been told anything about methods or prostitutes of a Field object. Both Library objects and Entry objects have title, so it might exist, but maybe not.

Maybe what you should do is show us the structure of your library and then tell us what you want to do, and I bet you'll get several responses from the forum on that.

Bill Crews

unread,
Dec 7, 2020, 11:37:00 AM12/7/20
to Sebastian Amigon, mementodatabase
Actual, I looked it up, and there's no way to get a Field object, field (normally) returns a String object, such has only one property: length. But in this case, campo is null, so that doesn't happen.

Yes, showing us your structure and what you want to do is the right way to go.

Sebastian Amigon

unread,
Dec 7, 2020, 12:59:19 PM12/7/20
to mementodatabase

what I want is that when the field "Avance calculado" is updated, send me an email, it should work with an if (field.title == "Avance calculado") but the issue is that it does not work for me due to the error of the properties .title and .value, I already tried doing real updates but the trigger is not executed,  it is not even executed with the simplest script  
imagen_2020-12-07_115127.png

Er Mo

unread,
Dec 7, 2020, 1:44:40 PM12/7/20
to mementodatabase
Hallo
Du brauchst den Trigger " Bei Änderung " . Der löst aus wenn ein bestähenter Eintrag wieder Gespeichert wird . Da müsstest du ein Skript einsetzen das die Änderung erkennt und das E Mail absetzt .

Saluton
Vi bezonas la ellasilon "Surŝanĝo". Ĉi tio ekfunkciigas kiam konfirmita eniro denove estas konservita. Vi devus uzi skripton, kiu rekonas la ŝanĝon kaj sendas la retpoŝton.

Er Mo

unread,
Dec 7, 2020, 2:45:58 PM12/7/20
to mementodatabase
Hallo
Versuche mal das Skript . Trigger erstellen unter " Überarbeite einen Eintrag " -> " Bevor der Eintrag gespeichert wird " . In einen Eintrag das Feld " Avance " ändern -> Speichern . Da müsste einen Meldung kommen "  Änderung "

Hello
Try the script. Create triggers under "Revise an entry" -> "Before the entry is saved". Change the "Avance" field to an entry -> Save. There should be a message "Änderung"


Skript:
var e= entry()
var F1 = "Clave"
var F2 = "Avance"
var Aus = " alles Gleichgebliben "
var tesn = e.field(F1)
var datn =e.field(F2)
var libclients = lib();
var entries = libclients.entries(F1);
var l = entries.length;  
for(var j=0;j<l;j++){
var dat =entries[j].field(F1)
if(dat == tesn){
var data =entries[j].field(F2)
if (data != datn)  Aus = " Änderung "
}
}
message (Aus)

Gilles Mons

unread,
Dec 8, 2020, 3:40:29 AM12/8/20
to Er Mo, mementodatabase
Hello,

The script doesn't seem to work ....

I thought that the option "Update a field" in the Trigger scripts will prevent "for" loops in the library, but it seems not .....

Has anyone able to explain how the "Update a field" option works in Trigger scripts ....?

I asked the support, but to date no feedback ....

Gilles
"Hello and thank you" are the magic words in my world....

Er Mo

unread,
Dec 8, 2020, 4:40:15 AM12/8/20
to mementodatabase
Hallo Gilles
Ich habe den Trigger in der PC Version zum Auslösen gebracht , wenn ich in der Tabellen Ansicht ein Feld geändert habe . Ich Glaube das ER nur für das Abfangen dieser Änderung bestimmt ist .

Hello Gilles
In the PC version, I made the trigger trigger when I changed a field in the table view. I believe that ER is only meant to intercept this change.

Bill Crews

unread,
Dec 8, 2020, 7:40:23 AM12/8/20
to Gilles Mons, Er Mo, mementodatabase
I thought that the option "Update a field" in the Trigger scripts will prevent "for" loops in the library, but it seems not .....

Three are no limitations in trigger scripts or action scripts.

Has anyone able to explain how the "Update a field" option works in Trigger scripts ....?

In the Updating an Entry, you begin execution either just before saving the entry, in the Before Saving an Entry. You have access to all of JS 1.7 except for the Document Object Model the Web guys use -- all statements. You also have access to the Memento JS Library. Global functions you can call directly include entry(), lib(), exit(), cancel(), and others you can see in the wiki under Memento JS Library.

I don't know what you want to focus on. I don't think you want a full treatise on things you know already most of. At some point in the future before long, I'll put the full explanation into the wiki. Email me if you want more. It sounds like he thinks he's not getting a trigger event when Save occurs. This probably means the script is calling exit() or cancel() before the script has done anything he can see.

Just put a message("Received trigger"); at the beginning of the script to prove it's happening before doing anything else.

Sebastian Amigon

unread,
Mar 3, 2021, 10:29:37 AM3/3/21
to mementodatabase
Hi!
I have a problem with the trigger, I was doing tests with the example that you wrote here but it does not work, in the script editing section if the script works, but when I update a field the trigger does not runScreenshot_20210303-092212.png

Bill Crews

unread,
Mar 3, 2021, 11:13:27 AM3/3/21
to Sebastian Amigon, mementodatabase
I'm confused. You say "example you wrote here". What example I wrote where? I know of no such example. Your code should not work. The field() method requires an argument, but you don't provide one. To which field do you intend to be referring? I'm not surprised that running the script works, though, since using no argument in a JS method call is not an error. Provide a fieldname that matches the name of a field in your library, and we "can be in business", as we say.

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

Sebastian Amigon

unread,
Mar 4, 2021, 11:11:47 AM3/4/21
to mementodatabase
Excuse me, so if it's not too much trouble, could you give me an example? it would really help me

Er Mo

unread,
Mar 4, 2021, 11:31:12 AM3/4/21
to mementodatabase
Hallo
Für was brauchen sie ein Beispiel ? Wie sie den Inhalt eines Feldes abfragen .

Hi
What do you need an example for? How to query the content of a field.

Er Mo

unread,
Mar 4, 2021, 11:53:02 AM3/4/21
to mementodatabase
Hallo
Das Skript lässt eine Meldung am Bildschirm erscheinen ( " Test ")

Hi
The script displays a message on the screen ("test")

message("Test")

Bill Crews

unread,
Mar 4, 2021, 4:25:07 PM3/4/21
to Er Mo, mementodatabase
As I recall, the Updating a field trigger does not fire the trigger when multiple entries are selected ... yet. Is that what is happening here?

Reply all
Reply to author
Forward
0 new messages