Set Boolean field true or false via Trigger

78 views
Skip to first unread message

Thomas Bauer

unread,
Feb 9, 2017, 6:22:55 PM2/9/17
to mementodatabase
I have a boolean field called "Anzeige".
I want to change the field from false to true or from true to false.
I tried it with a simple script.
var e = entry ();
e.set ("Anzeige", true);

But it does not work.

I have the error messages attached.
Where is my thought mistake
Screenshot_2017-02-10-00-08-26.png

Bill Crews

unread,
Feb 9, 2017, 7:25:19 PM2/9/17
to mementodatabase
That should work. The error is on line 2, a reference to a null object. The only object referenced on line 2 is e, but you've properly defined and initialized e. If understand the German correctly, this is a Before phase, so the entry object should exist.

JavaScript can issue weird error messages sometimes, so also make sure the field Anzeige is really there, spelled and capitalized correctly.

That's all I can think of.

Thomas Bauer

unread,
Feb 10, 2017, 10:14:13 AM2/10/17
to mementodatabase
Bill,sometimes I do not understand the world.
I do not know if this sentence makes sense in English.

After you told me that this script should work, I have created a small test library.
Only 2 fields. An integer field as a unique field for the name and a boolean field with the name "display". I copied the trigger script from my workout library. At the test library it worked. Then I deleted the trigger in the workout library. Then I copied the script from the test library back and now it works also in my workout library.

But this is just the first part.

This boolean field should be set to true automatically when creating a entries. If the entrie stored, the boolean fied is to be set to false.

I want to control the dependencies of each field.
Some fields are then visible only at the first opening.
Next time not more. So you can not change the entries.

I've tried it in 4 different ways.

1 entryDefault().set("display", true);
      Trigger settings:  Creating an entry; Opening an Entry Edit card
      it does not work but no error

2 entryDefault().set("display", true);
      Trigger settings:   Updating an entry; Opening an Entry Edit card
      it does not work but no error

3 var e = entry();
   e.set("display", true);
      Trigger settings:   Creating an entry; Opening an Entry Edit card
      it does not work but no error

4 var e = entry ();
   e.set("display", true);
      Trigger settings Updating an entry; Opening an Entry Edit card
      is working. But too late. Fields should be visible when creating and not
      When updating

Is there a solution here?

Bill Crews

unread,
Feb 10, 2017, 10:58:29 AM2/10/17
to mementodatabase
Part of what you want is easy, I think, as one can set the initial value of a Boolean field by checking the Default button when creating the field and indicate which value it should have. That might be more difficult if you really mean Checkboxes.

Also, putting fields on separate pages could help a bit. The other thing we could do is to use triggers to keep people from changing the values of fields (I think, one possible issue). But I don't believe Memento can do the following:
- set a dependency on a page, which would be nice
- manipulate library structure from a trigger (that includes dependencies)

I think you can accomplish the overall task with Memento, but I'm not sure if it will be user-friendly enough for you.

Thomas Bauer

unread,
Feb 10, 2017, 12:35:46 PM2/10/17
to mementodatabase
I know the problem with the dependencies on pages, but I only use this at subheaters.
In my workout library I work with link to entry fields with the pictures for my exerciseexplanations. as you know.
Since I do not know how I can copy this from the last traing day into a new entry.
I create a new entry over copy the last entry. Do you understand? (Look to my image)
This does not work with the default button. This is only possible if you create an entry via the + button.

Securing over trigger, so entries can not be changed, is more difficult than to hide entries.

Do you have an idea how to set the boolean field, while opening an entry
Screenshot_2017-02-10-18-15-23.png

Bill Crews

unread,
Feb 10, 2017, 1:51:38 PM2/10/17
to mementodatabase
You ask several questions:
1. I will try using a trigger to copy the link from the previous entry. To do that, I have to learn what sequence I can count on the array being in, so I don't have sort it or search it, which would time-consuming. I'll learn if there are any hitches in copying the value of the field between entries. Please, make a list of all field types you want to use to prime a new entry. This will be great stuff for the wiki.

2. If you can use dependency visibility and not need a trigger, that's clearly better. As of this moment, I don't know how, though. Maybe if I get the copy working, that will enable using dependencies and default values (via using the + button), as well.

3. Maybe, we'll get to where you can use a default value. I believe that Memento inserts the default value, but that it doesn't display until after the entry is saved; that's not good enough for your needs, is it? Using a trigger to set the value will likely also have this same limitation.

I'll post again after I've tried the copying.

Thomas Bauer

unread,
Feb 10, 2017, 2:18:35 PM2/10/17
to mementodatabase
I only need 2 field types
Integer fields and link to entry fields.
For the integer fields you already have an example in your wiki.
I am missing only one solution for the Link to Entry fields.

For the rest of your post, I need more time to translate

Thomas Bauer

unread,
Feb 13, 2017, 11:42:28 AM2/13/17
to mementodatabase
Bill, I've finished the trigger to copy the integer fields of my workout library. It works well.
Here I have the following idea. 
For the integer values, I need the values from the last training. 
In the link to entry fields do not. Since they are information about the exercises, they never change. They are constants. 
Therefore they do not have to be read out of the last training in a trigger. They only need to be set.
In about:  e.set ("link to entry", chestpress info);
Is this right?

Bill Crews

unread,
Feb 13, 2017, 2:44:46 PM2/13/17
to mementodatabase
Sorry I haven't reported back; I've been busy.

I have so far failed to use set() to affect an lte field in any way. I've asked Vasya for assistance. He's even more busy than I. Hopefully, I will learn how to do it. What I hoped would work is...

entry().set("lte2", entry().field("lte1"));

...though I've tried other variations, as well. No luck so far.

Eugene Kartoyev

unread,
Feb 13, 2017, 2:55:48 PM2/13/17
to mementodatabase
entry().set("lte1", entry().field("lte2")); // at opening, before view

Worked fine. Tested for text and boolean.

Thomas Bauer

unread,
Feb 13, 2017, 3:40:16 PM2/13/17
to mementodatabase
I do not quite understand it.
I have a library with name "workouts".
In it there is a link to Endry calls "Brustpresse Info".
This is linked to the library "Übungshilfen".
When opening before view.
From the library "Übungshilfen" the entrie "Übungsanleitung Brustpresse" should be set.

entry().set("lte1", entry().field("lte2")); 

for "lte1" i think i write  "Übungshilfen".
But what means "lte2"

Thomas Bauer

unread,
Feb 13, 2017, 3:42:33 PM2/13/17
to mementodatabase
Screenshot_2017-02-13-21-11-46.png
Screenshot_2017-02-13-21-11-27.png
Screenshot_2017-02-13-21-08-00.png

Bill Crews

unread,
Feb 13, 2017, 4:58:48 PM2/13/17
to mementodatabase
My code was just like yours, but in a CreatingBefore trigger. I close the edit card, reopen it, and lte2 does not change. The field shows as array, of course, but its length is 0.

Bill Crews

unread,
Feb 13, 2017, 5:01:46 PM2/13/17
to mementodatabase
I was setting lte1 manually and using set("lte2", e.field("lte1")); to set the other.

Bill Crews

unread,
Feb 13, 2017, 5:07:42 PM2/13/17
to mementodatabase
Thomas, right now, I'm just trying to copy one link to entry (lte) field to another. Once I can do that, I can do the same across entries or even libraries. If Eugene says it works in other event phases, I'll try that. We could probably use the Opening an edit card phase. I never tried it.

Thomas Bauer

unread,
Feb 13, 2017, 5:54:12 PM2/13/17
to mementodatabase
I have created a small library with 2 LTE.
It's called testing
The linked library is called exercise aids.
From the trigger I have attached an image.
It does not work.
You have access to the libraries.
Screenshot_2017-02-13-23-35-38.png
Reply all
Reply to author
Forward
0 new messages