This is my last Hope

429 views
Skip to first unread message

D M M

unread,
Jan 7, 2022, 6:53:15 PM1/7/22
to mementodatabase
I used to be a database programmer so im pretty well versed in the relationships and the code. I chose memento so I could develop an app on my phone.

I have searched and tried so many different things and wasted so much time trying to do something SO simple which tells me
a. It's due to a limitation with Memento or
b. Its something so obvious I will kick myself for missing in the first place!

Many others before me have asked the same question and I have tried their solutions with no luck.I have also looked thru existing Library templates for an answer and gave up.

I have 2 libraries Parent and Child - the relationship "should" be 1 to Many, however I have also tried this Many to Many with the same results. The relationship between the 2 libraries is established using a Link to Entry field in Parent linked to the Child Library

Parent
->LastName
->FavoriteColor
->Relative (Linked Entry field to Child library)

Child
->LastName
->FavoriteColor

I want to be able to create a new entry in Child via hitting the "+" associated with Relative from the Parent library. Then just copy the field LastName (Parent) to corresponding field LastName (Child).

I have a trigger script (Child) set up with events Creating an Entry/Opening an Entry Edit card . Both libraries permissions are set to access each other.
I started with the simple example from various outlined in several posts with events  Creating an Entry/Opening an Entry Edit card . (see Trigger 2)
The problem is the LastName field (Parent) is coming in as Null when i run this (see Trigger 2 run) I am unable to access the value of the (Parent) LastName field.

The CLOSEST I have come to actually getting the thing to work is like this (see Trigger 1)
The problem is I don't know the actual position in the array of the Parent entry associated with the new Child. Position 0 only references the last modified entry in the array, which doesn't help me. (see Trigger 1 run)



child.PNG
trigger 1 run.PNG
trigger 2 run.PNG
trigger1.PNG
parent.PNG
trigger2.PNG

Bill Crews

unread,
Jan 7, 2022, 8:25:52 PM1/7/22
to D M M, mementodatabase
Yeah, Memento is relational-ish, but not relational. Here's the deal from my angle at the design level. I'm sure you'll get others responding at the coding level ...

If you've read my posts over the years in the forum, you know that I strongly consider Memento's forte to be in the child's entries list, using all the functions of the right-side menu (in the Mobile edition, anyway. I don't know the Desktop edition so well.). I refer to these as slicing & dicing. They are Sorting, Grouping, Filtering, Charting, and Aggregation.

Use sorting & grouping on the fly. Use charting & filtering -- especially filter tabs! -- in a more sustained manner. The power of these tools on this screen just blows away tahe capabilities offered the user in the parent's entry view/edit cards!

In relational, you can have it either way any time, but in Memento, the links are directional, so it's one way or the other, the link in one library or the other (I've done it both ways, by the way). So, the parent's list you describe is just a dead list, with not much if any slicing & dicing, and I can see that, if you are entering a parent entry, havent saved it yet, add some child entries, and they have triggers, then of course, the parent entry's field values are not save yet and are thus undefined or null or whatever.

If you work in the child library with a one-to-many link (or many-to-many, if that fits the user process model) from the child to the parent, I'd have to think about it further. Which library gets the trigger script is unclear to me -- depends on the script. But if you add a parent entry from the child side, the script is probably not dependent on the existence of child information. Is that right? AND you get the benefit of child-centric database design! (Yay!)

Try it! Let us know what you learn from that, please.

--
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/a2a00933-9374-44d1-96ad-006869c23429n%40googlegroups.com.
Message has been deleted

D M M

unread,
Jan 8, 2022, 12:55:08 AM1/8/22
to mementodatabase
So I re-read your response several times and I wanted to mention wrt your statement above:
So, the parent's list you describe is just a dead list, with not much if any slicing & dicing, and I can see that, if you are entering a parent entry, havent saved it yet, add some child entries, and they have triggers, then of course, the parent entry's field values are not save yet and are thus undefined or null or whatever.

when I was trying this (see Trigger 2 run) I had already saved the Parent entry "Johnson" when I ran my script. So in this situation, when I went to add a Child entry (having the trigger script 2) the Parent entry LastName field already had the value of "Johnson" - and yet it still returned Null for the field value .

Thoughts?

Beth Dixon

unread,
Jan 8, 2022, 9:25:09 AM1/8/22
to D M M, mementodatabase
Hi there, can you send a screenshot of the actual script.  May help the forum pinpoint the problem.  Sometimes it's just simply overlooking the adding of JavaScript libraries.  Sometimes more complicated.

- Beth

Er Mo

unread,
Jan 8, 2022, 9:52:23 AM1/8/22
to mementodatabase
Hallo
Sie haben die Skripte ausführen lassen beim " Öffnen der Eintragskarte " Wenn die Eintragskarte geöffnet wird, wird der Feldwert von " LastName " geholt und Angezeigt . Da du ja vor den Öffnen nichts Eingetragen hast ist der Wert " Null" . Versuche es " Nach den Speichern " . Es kann vorkommen das die Anzeige schneller ist als der Eintrag und momentan nichts Anzeigt . Aber wenn du die Anzeige erneut öffnest , ist es Eingetragen .

Hi
You ran the scripts when "opening the entry card". When the entry card is opened, the field value is fetched from "LastName" and displayed. Since you have not entered anything before opening, the value is "zero". Try "after saving". It can happen that the display is faster than the entry and currently does not display anything. But when you open the ad again, it's Registered.

D M M

unread,
Jan 8, 2022, 12:05:38 PM1/8/22
to mementodatabase
They are in the attached files in my first post

D M M

unread,
Jan 8, 2022, 12:08:37 PM1/8/22
to mementodatabase
When you say LastName are you referring to Parent or Child? All Child fields will definitely be null when it's created, the problem is I'm trying to access the Parent LastName field from a trigger script located in Child and the value is being returned as Null. (See trigger 2 above).

Beth Dixon

unread,
Jan 8, 2022, 12:27:31 PM1/8/22
to D M M, mementodatabase
Ahh, that went to my spam folder.  

- Beth

Er Mo

unread,
Jan 8, 2022, 3:29:07 PM1/8/22
to mementodatabase
Hallo
Ja Trigger 2 wird ausgeführt wenn ein neuer Eintrag erstellt wirt . Genau dann wenn die Eintragskarte sichtbar wird . In diesen Augenblick ist das Feld " LastName" leer . Wenn du das Feld " LastName" ausgefült hast und du den Eintrag Speicherts , gibt es einen Wert in Feld "LastName" . Darum musst du den " Event " auf " Eintrag erstellen "  --> " Nach den Speichern  " umstellen .

Hi
Yes Trigger 2 is executed when a new entry is created. Exactly when the entry card becomes visible. At this moment the "LastName" field is empty. If you have filled in the "LastName" field and you save the entry, there is a value in the "LastName" field. Therefore you have to switch the "Event" to "Create entry" -> "After saving".

Bill Crews

unread,
Jan 8, 2022, 4:55:30 PM1/8/22
to Er Mo, mementodatabase
These are clearly test databases, presumably with test data, as well, so you should be able to share links to these libraries without security concerns. Please do so, and provide public access permission & Allow all functions.

I think those pursuing this angle will best be able to help using access to those libraries, putting in their own test data, or inserting debug statements within scripts.

From my angle, let me know if you redesign as we discussed previously. Or if you share the libraries, I could copy them, and create a new pair of libraries & test the child-centric implementation myself & let you know the result. None of this should take very long to do.

D M M

unread,
Jan 9, 2022, 2:42:02 PM1/9/22
to mementodatabase
let me know if it changed to public and I have pushed the libraries to the cloud . Here is the link for Parent


and for Child

Beth Dixon

unread,
Jan 9, 2022, 7:23:28 PM1/9/22
to D M M, mementodatabase
Hi there, try this Action script....see attached screenshots.  It works.

Beth

Screenshot_20220109-191920_Memento Database.jpg
Screenshot_20220109-192205_Memento Database.jpg
Screenshot_20220109-192147_Memento Database.jpg

Er Mo

unread,
Jan 10, 2022, 12:20:37 PM1/10/22
to mementodatabase
Hallo
Du muss in der Bibliothek "Child" die Erlaubnis erteilen das sie auf die Bibliothek " Parent " Zugreifen kann .Für die Mobilversion , Skripte Öffnen --> auf das Schilt ober Recht Kliken " Berechtigungen für Trigger " in den " Verfügbare Sammlung " die Bibliothek " Parent " auswählen .

Hi
You have to give permission in the "Child" library to access the "Parent" library. For the mobile version, open scripts -> click on the right click on "Authorizations for triggers" in the "Available collection" in the library Select "Parent".

Ernst

D M M

unread,
Jan 16, 2022, 8:42:10 PM1/16/22
to mementodatabase
Hey Beth,

I tried to add the script you wrote both as a trigger and an action neither worked so im wondering if I have the parameters set incorrectly? Was this a trigger script and if so what did you have set as the actions? I see Entry view on card but nothing else.

Beth Dixon

unread,
Jan 16, 2022, 9:59:09 PM1/16/22
to D M M, mementodatabase
Hi there DMM,

I hope I understand what you are trying to accomplish.  Do this on your mobile edition  NOTE:  BEFORE YOU TRY THE SCRIPT VERSION TRY THE MOVE OR COPY OPTION I LIST BELOW.

This is what I did:
In the Parent library I created two text fields - LastName, and Favorite Color and a Linked to Entry field to the Child library.  (Relationship is One to Many)
In the Child library I created two text fields - LastName, Favorite Color, and an integer field called Age.

Then in the Parent library I created an Action script as follows:
Tap on Add javascript libraries
Place of Action is Entry view card

Script - 
var there = libByName("Child")'
var newEntry = new Object();

newEntry["LastName"] = entry().field("LastName");
newEntry["FavoriteColor"] = entry().field(FavoriteColor");
there.create(newEntry);

This script will copy the LastName and Favoritecolor fields from the Parent library to the Child library.  If you have more fields in the Parent library that you want to copy to the Child library just enter them the same as above.  (newEntry["Your field name in Parent library"] = entry().field("Your field name in Child library")
Then in the Child library you enter the age and link the entry to the Parent library entry.

Do this as follows:
In Parent library create a new entry.
LastName = Doe
FavoriteColor = Blue
Create the entry.
Once created tap on the "Doe" entry, then tap on the arrow in the upper right corner.  This action creates an entry in the Child library.  Close Parent library, open Child library.  Tap on pencil for the entry and edit accordingly.  You link this entry to the parent entry at this point as well.

If you want to copy more than one field you could also try this method....might be simpler and doesn't involve scripting.  MOVE OR COPY OPTION
1.  Tap on your entry in the Parent library.
2.  Tap on three dots in upper right corner.
3.  Select Move or Copy
4.  Tap on Blue + at bottom right corner.
5.  Select your Child library.
6.  All you fields will be listed.  For example the field LastName in Parent library will be copied to LastName field in Child library.  You can define the field to copy to by tapping on the entry.
7.  At the bottom of the mobile device screen check the box Create a copy and then save.  
8.  Hit back arrow.
9.  Tap three dots in upper right corner again, tap Move or Copy.  A message at the bottom should appear to say a An entry has been copied to the Child library.  
10.  Tap on pencil. tap on lines in link to entry, and tap on corresponding name to link the entries.  Then edit the Child entry as desired.

If you don't like this method, go ahead and try the script method.

Beth



D M M

unread,
Jan 17, 2022, 10:39:04 PM1/17/22
to mementodatabase
ok
I tried to respond in text to your post but it wont let me do that
SO heres the best I can do:-)

Script - 
var there = libByName("Child")'
var newEntry = new Object();

newEntry["LastName"] = entry().field("LastName");
newEntry["FavoriteColor"] = entry().field(FavoriteColor");
there.create(newEntry);

This script will copy the LastName and Favoritecolor fields from the Parent library to the Child library.  If you have more fields in the Parent library that you want to copy to the Child library just enter them the same as above.  (newEntry["Your field name in Parent library"] = entry().field("Your field name in Child library")
Then in the Child library you enter the age and link the entry to the Parent library entry.(if the Parent is already linked to the child record why do I have to then link the child back to Parent? This seems redundant.)

Do this as follows:
In Parent library create a new entry.
LastName = Doe
FavoriteColor = Blue
Create the entry.
Once created tap on the "Doe" entry, then tap on the arrow in the upper right corner.  This action creates an entry in the Child library.  Close Parent library, Why?? I want to complete the age field for the child record and then return to the Parent Entry for Doe. open Child library.  Tap on pencil for the entry and edit accordingly.  You link this entry to the parent entry at this point as well.

Where in the documentation does it state there needs to be a circular link between Parent->Child->Parent ?
Writing scripts are no issue, I just need them to work lol.
Thoughts?

Gilles Mons

unread,
Jan 17, 2022, 10:54:37 PM1/17/22
to D M M, mementodatabase
Bonjour DMM,

Je vais essayer de vous aidez :

Il y a quelques temps j'ai écrit un script qui permet de modifier un champ dans un enregistrement, sans réécriture de l'enregistrement complet, cela peut vous servir 

var e = entry();
//X2 Table
var LBNx2 = libByName("X2 fr");
var entriesx2 = LBNx2.entries();
var l2 = entriesx2.length;
//X1 Table
var name1 = e.field("Nom 1");

//
for ( var i=0;((i<l2)&&(name1 != name2));i++)
{

var name2 = entriesx2[i].field("Nom 2");

var id2 = entriesx2[i].id;

var recordId2 = LBNx2.findById(id2);

if ( name1 === name2 )
  {
  recordId2.set("Résultat 2",e.field("Résultat 1"));
  }
};

Les tables s'appelle X1 fr et X2 fr, il semble que vous soyez à l'aise avec les scripts donc cela peut vous aider.

Je vous joint les tables exemples.

X1

X2
Gilles.


Hello DMM,

I will try to help you:

Some time ago I wrote a script that allows you to modify a field in a record, without rewriting the whole record, it can help you:

var e = entry();
//X2 Table
var LBNx2 = libByName("X2 fr");
var entriesx2 = LBNx2.entries();
var l2 = entriesx2.length;
//X1 Table
var name1 = e.field("Nom 1");

//
for ( var i=0;((i<l2)&&(name1 != name2));i++)
{

var name2 = entriesx2[i].field("Nom 2");

var id2 = entriesx2[i].id;

var recordId2 = LBNx2.findById(id2);

if ( name1 === name2 )
  {
  recordId2.set("Résultat 2",e.field("Résultat 1"));
  }
};


The tables are called X1 fr and X2 fr, it seems that you are comfortable with scripts so it can help you.

I attach the example tables.

X1

X2

You received this message because you are subscribed to a topic in the Google Groups "mementodatabase" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mementodatabase/ZQaEgksfS_s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mementodataba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mementodatabase/5439e762-c4b9-46eb-b1ba-006cae2b19cbn%40googlegroups.com.

D M M

unread,
Jan 17, 2022, 11:08:44 PM1/17/22
to mementodatabase
Beth,

I just noticed something different - I am actually editting the Parent Entry for Doe - in edit mode is where I click on the "+" to create a new Child entry. When I try this using the script it doesnt automatically fill in the LastName field for the Child. This is why I was using Triggers versus actions.

What you describe is to select the Parent entry for Doe and from there click on the arrow to create the child entry - which it does do btw :-) and the Child entry does have "LastName" of Doe.

Is there a way to do this from within edit mode? Ideally I would be entering a new Parent Entry and then would want to populate associated Child entries while in edit mode.

Beth Dixon

unread,
Jan 18, 2022, 12:00:36 AM1/18/22
to D M M, mementodatabase
Sorry DMM, I am out of ideas.  :(

- Beth

Reply all
Reply to author
Forward
0 new messages