How to automatically put the file title into dataview query

I am trying to the automatically put the file title (writer’s name) into a dataview query. If I type in “Aaron Jones” between the brackets, it works fine. I have almost 200 files to edit, so I thought I could automate it.

I have tried using an inline dataview query within this query but it did not work (between the brackets I added = this.writer)

Thanks in advance. Sorry if I did not format my topic correctly (newbie, here).

You access the current file title using this.file.name.

Thanks. I just tried that and it did not work. I do appreciate the help, though.

That is weird, on my end it worked just fine.

Maybe I didn’t understand what you’re trying to achieve, because this.file.name returns exactly the current note title where the code is declared in.

1 Like

I will keep trying and report back. Did you try this inside of a dataview query?

Of course, that was the whole point in your post :slight_smile:

And I assume you didn’t put “this.file.name” within [[ ]]

Yes, didn’t work.

In a standard DQL query like your example, the this.file.name should work to get the actual name of the file. If you want the writer field from the current file, you should use this.writer. So a little depending on whether you actually want the file name or a link, your query looks differently:

Just the name

```dataview
TABLE
FROM "Books"
WHERE writer = this.file.name
SORT file.name ASC
```

This would require that each book has a single property of the form: writer: Aaron James.

Links

In the case of links, it would look like:

```dataview
TABLE
FROM "Books"
WHERE writer = link(this.file.name)
SORT file.name ASC
```

Which would require that each books a single property like in: writer: "[[Aaron James]]"

What about multiple authors?

And this is where it gets tricky if your books have one or more writers. Since that require some trickery to force every entry into being a list and checking against that list. Given a list of names (not links) the query would then look like:

```dataview
TABLE
FROM "Books"
WHERE econtains(flat(list(writer)), this.file.name)
SORT file.name ASC
```

With the variation of link(this.file.name) (instead of this.file.name) if writer in the books is written as a list of the form:

writer:
- "[[Aaron James]]"
- "[[William Shakespeare]]"
1 Like

Thank you for the thorough explanation. I used the example you showed for links and this works fine. I apologize to @woofy31 - in my books files, the value for writer is formatted as a link. I did not realize this when I posted this topic.

Now I can use Linter to add this dataview query to the 150 or so writer files.

Again my thanks to both of you for your suggestions.

1 Like

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