Filter by user field

147 views
Skip to first unread message

Amundsf

unread,
Apr 16, 2025, 7:12:56 PM4/16/25
to mementodatabase
Hi

I'm trying to find a record in library User by the current user name. The library to find it in is People and the field name is User name. It's only 1 user in the field. 

I have tried a few variants. In example this:
let usrName = user();

list = list.filter(people => people.field("User name")[0]."User" == usrName);

This is and other variant I have tried is wrong, how is it done? I have tried to search, but have'nt found an example. 

Thanks a lot in advance 
Amund 


Er Mo

unread,
Apr 17, 2025, 1:09:03 PM4/17/25
to mementodatabase
Hallo
Du musst in der Bibliothek suchen .also:
var list = libByName("Bibliothek").entries()
so ich " list " der Inhalt der Bibliothek die du durchsuchen willst

Hello
You need to search the library. So:
var list = libByName("Library").entries()
So "list" is the contents of the library you want to search.

Ernst

Amund Stigen Fjeld

unread,
Apr 17, 2025, 2:02:41 PM4/17/25
to mementodatabase
Hi

Yes, that is done earlier in code and I fetch records. 

The question is how to do filter on a field type User. 


Thank you
 - Amund

--
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/bG7E-K5bVqU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mementodataba...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mementodatabase/53525545-52b4-4873-8c1f-b0f17a74a8e8n%40googlegroups.com.

Amundsf

unread,
Apr 23, 2025, 1:55:28 PM4/23/25
to mementodatabase
Hi again

No one that know's how to do a filter for entry list (by field type User?

I get current userName:
let usrName = user();

I have initialized the list like:
var lib = libByName('People');
var list = lib.entries();

Then I need to do the filter on fieldName User Name in library People. I have tried several variants like this, but I haven't found anything working:
list = list.filter(people => people.field("User name")[0]."User" == usrName);

Thank you
 - Amund

Bill Crews

unread,
Apr 23, 2025, 7:24:36 PM4/23/25
to Amundsf, mementodatabase
For one thing, you spell userName also as usrName.


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 visit https://groups.google.com/d/msgid/mementodatabase/61adcfb7-58d2-4cd9-a2bb-4134aec056dcn%40googlegroups.com.

Amund Stigen Fjeld

unread,
Apr 23, 2025, 7:49:42 PM4/23/25
to mementodatabase
"User name" is the field name (as of type User) in library to do filter on. 

usrName is the current logged in user (retrieved from = user() ). 

My guess is that the wrong part is the yellow here:
"User name")[0]."User" == usrName

This part is inspired by how doing a filter for L2E field is done. The error then is missing name after operator. 

I have tried "User name")[0] the error then is Cannot read property "0" from null. 

If I reduce it to "User name") = usrName there is no error, but the list don't have any records. My guess is that it's because field type User can have several users - that's why I tried solutions as above with [0] 

 - Amund

Mmm

unread,
Apr 23, 2025, 11:43:35 PM4/23/25
to mementodatabase
Вы пытаетесь сравнить объекты (будет всегда false). 

Попробуйте так:

let list = lib().entries();
let usrName = String( user() );

list = list.filter(people => String( people.field("User name") ) == usrName);

message( list.length );

четверг, 24 апреля 2025 г. в 02:49:42 UTC+3, Amundsf:

Mmm

unread,
Apr 24, 2025, 1:32:12 AM4/24/25
to mementodatabase
Если поле "User name" содержит несколько объектов (пользователей), то попробуйте так:

const users = obj => {
    let arr = [];
    if (obj) {
        let user = obj;
        arr = [String(user)];
        while (user.hasNext) {
            user = user.next;
            arr.push(String(user));
        }
    } 
    return arr;
}

let list = lib().entries();
let usrName = String( user() );

list = list.filter(people => users(people.field("User name")).includes(usrName));

message( list.length );

четверг, 24 апреля 2025 г. в 06:43:35 UTC+3, Mmm:

Er Mo

unread,
Apr 24, 2025, 1:14:27 PM4/24/25
to mementodatabase
Hallo
Der Zurückgegebene User kann nur 1 Mal sein . Es könne nicht 2 Personen in Memento angemeltet sein . Daher gehe ich dafon aus das beim Abrufen von user() das " [0] " Falsch ist .

Hello
The returned user can only be one. Two people cannot be logged in to Memento. Therefore, I assume that "[0]" is false when calling user().

Ernst

Amund Stigen Fjeld

unread,
Apr 24, 2025, 1:28:08 PM4/24/25
to Er Mo, mementodatabase
Hi

This soluton for Mmm worked 🙂:
let list = lib().entries();
let usrName = String( user() );

list = list.filter(people => String( people.field("User name") ) == usrName);

I only have one user in the field so that's working for me, I haven't trid your suggestion if several users in the field.

Ernst:
Yes, only one people can be logged in, but the field in the library can possibly have several users. But not in my case now 🙂

 - Amund



Er Mo

unread,
Apr 24, 2025, 2:40:27 PM4/24/25
to mementodatabase
Hallo
Ich bin jetzt von den Befehl " user() " ausgegangen

Hello
I'm assuming the command " user() "

Ernst
Reply all
Reply to author
Forward
Message has been deleted
0 new messages