Dataview retrieving data from inline field v. YAML

Things I have tried

I’m using my vault to manage information on contacts and meetings.

When I create meeting notes, I include an inline data field to list participants, and link to their respective contact notes. For any meeting, there can be several contacts listed.

Participants::

Then, in the contact note, I would like to use dataview to return a list of all the meetings in which that contact is listed as a participant. This is where I am having trouble. I have found that if I include “participants” in the YAML, I am able to retrieve the list of meetings using the following:

list 
WHERE type = "meeting"
WHERE icontains(participants, "NAME") 
SORT date desc

However, this same query will not work with the participants listed in the inline data field.

I’d prefer not to have to put the participant names in the YAML because I like having the link directly to the contact notes, and don’t want to have to write all the names twice.

What I’m trying to do

I’d appreciate any advice on how to format the inline data field and/or dataview query so that I can retrieve names from a listed array. I’m also open to suggestions on how to set this up in a better way that what I’ve have so far. Thanks.

We can’t guess what syntax you use in each case, inline and frontmatter.
You need to add all type of information about the format, the syntax, etc., to avoid this kind of reply.
For example, we don’t know how you add multiple values (an array) in each case. Or if you’re using links or strings!

Sorry, I’m new to a lot of this.

Inline text would like like:
participants:: [[Name 1]], [[Name 2]], [[Name 3]], [[Name 4]]

In the frontmater
participants: [Name 1, Name 2, Name 3, Name 4]

Up until now, I’ve been listing any meeting that links to a person’s name, but pulling from the array seems like a much neater solution, if I can get the syntax to work properly.

When the definition differs, the retrieval of that value would also differ. In the frontmatter you defined a list of names, and in the inline field you defined multiple links to names. These are not the same.

When looking at these using $=dv.span(dv.current()) it looks like this:
image

This is based on the following file (with a few additions of the definitions for clarity):

---
participants_frontmatter: [John FM Smith, Jane FM Smothers]
---
participants_inline:: [[John I Smith]], [[Jane I Smithers]]

You see how it lists the latter ones as links, and not just names?

I was a little intrigued by this format, so sorry for spoon feeding, but I found that the following table query would do the trick:

```dataview
table participants_inline as pi, P, PP
from "/"
flatten participants_inline as P
flatten meta(P).path as PP
where PP = "John I Smith"
```

which resulted in:
image

In the image see how the “base” field is showing both links in the pi column, whilst the P displays the link itself, and PP displays the text value (which is also used in the where clause).

Notice how I first use flatten participants_inline as P to split the links into multiple rows, and then secondly used flatten meta(P).path as PP to extract just the path part of the link. meta(...) accesses the link object, and allows for further investigations/queries on it. See meta(link) documentation.

I found that using TABLE was necessary for me to properly debug the various bits and pieces of the various fields, and at one point there was also a flatten meta(P) as PP just to show the various pieces of the link. Very useful stuff for debugging. The same stuff can also be applied to the list query (but then you can’t display multiple fields of course).

Hope this helps, and that you learned something from my lengthy text. At least I learned a little bit more about the flatten function, and how to process links in a DQL-query. :smiley:

Regards,
Holroy

Just some observations about @holroy observations :slight_smile:

meta(link).path has some limitations. In your sample it works because if file doesn’t exists you get only the name, not the “path”; if file exists in the root you get file.md as path; if file exists in folder “folderA” you get folderA/file.md. (by the way, this is useful to find notes that don’t exist, because dataview works only with files that exists :slight_smile: )

So, the point is: if “[[John I Smith]]” exists your query fails.

When we are dealing with existing links, one of the best ways to get the file name (the string of the title) is, in DQL, “going through” the link, ie, in your example, using p.file.name.

TABLE participants_inline as pi, P
FROM "your/folder/path"
FLATTEN participants_inline as P
WHERE P.file.name = "John I Smith"

Thanks for the correction, @mnvwvnm, I’m still learning this stuff, which is what triggered my response in the first place! :smiley:

1 Like

You can use the meta(link).path (as generic option for existent and non existent files), but you need to use regex to ignore all the rest and remains only the name (but I’m a dumb in regex… I can’t suggest the right code). :slight_smile:

All the rest of your point is absolutely right: @quinsca needs to decide if strings or if links.

So, this got a little bit uglier than expected. If file exists, the P.file.name could be used, but if it doesn’t exist it can’t be used. And further more, if the file exist the path-part changes to add .md to file name, in addition to prepending the folders, if there are any.

To counter all of this, and have a consistent response I found that the following seems to work:

```dataview
table   P, PP, PD, P.file.name, R
flatten participants_inline as P
flatten meta(P).path as PP
flatten regexreplace(meta(P).path, "^(?:.*/)?(.*)(?:\.md)$",  "$1") as R
where R = "Jane I Smithers" or R = "Bubba Bubbles"
```

The line with PP is not needed, it’s just used for display purposes, and showing the full path of the non-existing “Jane” file, and existing “Bubba” file in a sub-folder.
image

The regex has three distinct parts to it:

  • ^(?:.*/)? – Match from start of string, an optional non-capturing group of anything including a forward slash. This ensure the removal of the leading folder(s)
  • (.*) – Save the longest string possible into $1, which is used for replacement
  • (?:\.md)$ – Optionally followed by .md at the end of the string, in case the file exists already

Tested with a few more cases than I’ve shown, and it seems to work for both existing and non-existing notes, and for names with and without periods, .. So hopefully, this should be the better solution.

2 Likes

Great.
For a regex dumbs (like me) I can suggest this: FLATTEN default(P.file.name, meta(P).path) AS R
:slight_smile:

2 Likes

That option! Hehe…

That is so much prettier, than my solution. Why reinvent the wheel like I did, when such a useful function as default exists…

I stand in awe!

1 Like

This works. I really appreciate the spoon feeding, since I’ve been able to play around a bit more to get a table that suits my purposes.

Thanks, both.

1 Like

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