Bases: filter to match all notes that have properties with empty values?

What I’m trying to do

I’d like to create a filter that would show all notes that have empty property values. Excluding tags.

E.g. match a note with the following YAML:

---
tags:
hello:
---

But don’t match:

---
tags:
hello: there
----

Ideally, I wouldn’t need to write out each possible property into a formula. Though I’m ready to do this if need be.

Things I have tried

Uploaded the docs into ChatGPT and asked it for help—to no avail.

Ignoring tags for the moment, there’s a way to do All notes that contain a property, but it doesn’t have a value mentioned here:

https://forum.obsidian.md/t/bases-migration-quick-start-guide/101571#p-326077-query-all-in-note-with-a-specific-property-8

So, note.keys().contains("hello") and !hello || hello == null filters.

    filters:
      and:
        - note.keys().contains("hello")
        - "!hello || hello == null"

Hopefully that gets you started and others jump in with suggestions.

1 Like

For frontmatter properties excluding tags, I think this filter does it:

note.values().filter(value.isEmpty()).length - if(note.keys().contains("tags") && tags.isEmpty(), 1, 0) > 0

Not sure it’s the most efficient, but it’s what came to mind. If you find a cleaner way or notice an occasion where that doesn’t work, I’d love to know about it! And I could try to fix it.

Alternatively, if typing out each property, you could do:

and:
  - note.keys().contains("hello")
  - hello.isEmpty()
3 Likes

Dawni, I only tested the first part of your filter, because I’m only interested in notes with empty properties. So I added the filter note.values().filter(value.isEmpty()). It works, but Bases returns error: “Failed to evaluate a filter: Cannot find function “isEmpty” on type Boolean”.
But, again, it still works.

1 Like

Thanks for pointing that out! That actually means the filter misses some empty properties. To my understanding now that you’ve pointed out that error message:

When a note has a checkbox property with a value (either true or false but not null), my filter will reach that error and stop evaluating the note. If that same note has a different property that is empty, for example:

---
textCheckbox: false
aliases:
---

… then the filter might not “see” the empty property, and the note won’t show up in the results, even though we want it to.

I can’t immediately think of how to fix it wholesale—that is, without manually separating checkboxes from the other types of properties.

This is a case where a .type() function would be handy.

2 Likes

Well, v1.9.7 gives us a better solution. (Released right about the same time I posted the above, lol.) I think this covers Astrolupo’s situation with no error messages:

note.keys().length != note.values().filter(value != null).length

If you’re still cleaning your files, peeragetalkers, this looks like a cleaner solution:

note.values().filter(value == null).length - if((note.keys().contains("tags") && tags.isEmpty()), 1, 0) > 0
3 Likes

Thanks, dawni, this works perfectly, no error messages!

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.