Help with metadata menu query field

I have the current query that works:

dv.list(dv.pages('"TCPA/Notes/Documents"').where(p => dv.func.contains(p.linkedNotes, dv.current().file.name)).file.name)

For the life of me, I cannot figure out how to get this to work in a query field. Any suggestions? I’ve tried

dv.pages('"TCPA/Notes/Documents"').where(p => dv.func.contains(p.linkedNotes, dv.current().file.name)).file.name

with linkedNotes in the “name of related field”.

Can someone offer any guidance?

Using four backticks, ```` around your scripts produces a better visual:

```dataviewjs
dv.list(dv.pages('"TCPA/Notes/Documents"')
  .where(p => dv.func.contains(p.linkedNotes, dv.current().file.name))
  .file.name)
```

And

dv.pages('"TCPA/Notes/Documents"')
  .where(p => dv.func.contains(p.linkedNotes, dv.current().file.name))
  .file.name

I’ve also added some line break just to easier see what we’re working with.


OK, with the formatting out of the question, let’s try to answer your request. I’m further assuming that with “query field” you want to do this query as part of the text somewhere. One to notice then is that the ordinary inline query, `= … `, will mostly be used to lift information from the current file using this. If you want to query other files, you’ll need to use `$= … `.

So the following should in theory work:

`$= dv.pages('"TCPA/Notes/Documents"').where(p => dv.func.contains(p.linkedNotes, dv.current().file.name)).file.name `

This should produce a comma separated list of the file names matching your where clause.

1 Like

Thanks, that’s what I had I think. I think the problem must be with how I’m using metadata menu maybe.

if I have a field with spaces in it like “some field” you can just do some-field in dataview, or row[“some field”], neither of those seem to work in js. Is their a way to make that work, or do I just have to remove the spaces everywhere to make it work?

I’ve not used the metadata menu a lot, but another thread recently talked about how you should change something from select to file (if I remember correctly), which would allow for files to be returned from your query, and thusly skipping the entire space issue.

In an ordinary dataviewjs query, you can use the index notation to get to a spaced variable like in the following whimsical example:

my spaced key:: my spaced value

`$= dv.current()["my spaced key"]`

Where dv.current() is a page object as any others, like those returned in the chain from dv.pages().

1 Like