Linking entries with Trigger

89 views
Skip to first unread message

María Landa

unread,
Mar 5, 2026, 11:56:53 AM (12 days ago) Mar 5
to mementodatabase
Hello everyone,

I have two datasets and I'm trying to automate linking the last line one enters in one with the last line written in the other.
I created a field to entry field in the first dataset called "id" and I am trying to "fill" it automatically with a Trigger after saving the entry.
I am no expert on Java, so I don't really understand why it's not working.The code executes successfully but it is just not doing anything.

I am trying this, but I'm getting no results.

let obsLib = lib();
let idLib = libByName("ID");

let id = idLib.lastEntry();
let obs = obsLib.lastEntry();

obs.link("id", id);

Could someone help me? I'm sorry if it is a basic question, but I can't find the answer.

Thank you very much in advance.

María

Er Mo

unread,
Mar 5, 2026, 12:43:00 PM (12 days ago) Mar 5
to mementodatabase
Hallo
Du Hast 2 Verschiedene Bibliotheken und du möchtest in die Bibliothek " ID " eine Verlinkung einrichten .
 1 Hast du der Ausgehenten Bibliothek die Erlaubnis erteil auf die " ID " Bibliothek zuzugreifen ?
2. Auf welche Blattform arbeitest du ( Android , PC ,.. ) Es gib Unterschiede bei der Ausfürung .

Hello

You have two different libraries and you want to create a link to the "ID" library.

1. Have you granted the outgoing library permission to access the "ID" library?

2. Which version of the application are you using (Android, PC, etc.)? There are differences in how this works.

Ernst

Mmm

unread,
Mar 5, 2026, 2:03:12 PM (12 days ago) Mar 5
to mementodatabase
Решение вопроса всегда будет быстрее, если будут представлены упрощенные библиотеки или их шаблоны.
Не всегда описание пожеланий или перевод этих пожеланий создает полное представление о задаче.
четверг, 5 марта 2026 г. в 20:43:00 UTC+3, ernst...@gmail.com:

Mmm

unread,
Mar 6, 2026, 12:22:41 AM (12 days ago) Mar 6
to mementodatabase
Триггер Создание записи после сохранения на JavaScript:

let idLib = libByName("ID");
let ide = idLib.lastEntry();
if (ide) {
  entry().link("id", ide);


четверг, 5 марта 2026 г. в 22:03:12 UTC+3, Mmm:

María Landa

unread,
Mar 6, 2026, 4:21:22 AM (11 days ago) Mar 6
to mementodatabase
Hello everyone,

Thank you very much for your responses. It works!
I think there was an issue with the permissions, I revoked all of them and permitted again and it worked :) I'm doing this with the PC version.
Thank you for all your answers and the new code you proposed. It really helped.

I had an additional question. Would it be possible to specify that instead of "id" being the Last Entry on the library, it is the Last Entry the user wrote in the library? We are working several people in the same project, but I don't know enough Java to know if this option exists or not.

In my imaginary code it would be like:

let id = idLib.lastEntry(author=="me");

Does something like this exist?


The structure of the Libraries are: 
"ID" library for the characteristics of sites. with fields like: "City" "coordinates" "Temperature"
"Obs" for the sampling. Fields are "species" "time" "abundance" "id"

As I don't want to risk that two people are doing the sampling at the same time and it links one ID with the wrong Obs entry, that's why I am asking if this option of specifying one's last entry would be possible. Each user only has permission to read, write and delete their own entries. 

Thank you very much for everything!

María

Mmm

unread,
Mar 6, 2026, 5:32:06 AM (11 days ago) Mar 6
to mementodatabase
В библиотеке OBS нет поля с выбором Пользователя, поэтому предположил, что автор новой записи в OBS должен подключить свою последнюю запись из библиотеки ID.

Вариант скрипта на JavaScript (не Java!!!):

let e = entry(); 
let idLib = libByName("ID");
let idEntries = idLib.entries();

let curAuthor = e.author;
let filter = idEntries.filter(a => a.author == curAuthor);

if (filter[0]) {
    let ide = filter[0];
    e.link("id", ide);
}

пятница, 6 марта 2026 г. в 12:21:22 UTC+3, María Landa:

María Landa

unread,
Mar 6, 2026, 8:43:59 AM (11 days ago) Mar 6
to mementodatabase
Thank you very much!! It works perfectly! :) (JavaScript* sorry haha)
Reply all
Reply to author
Forward
0 new messages