How to make dataview inline JS expressions pull data from other note

Hello,

I try to use dataview inline js query to list values of a metadata key from another file/note.

I am able to recall data from another note with dataview inline query (not js):

`= [[notename]].keyname`

However, if the key includes multiple strings they are listed in a single line divided by comma. I want them to be inserted as a list on separate row, and thus use the dataview javascript function to replace comma with

I am able to recall frontmatter keys with multiple values with javascript with the replaceAll function from the same document by:

`$= dv.current().frontmatterkey.replaceAll(', ', '<br>')`

However, I am unable to combine the two methods to make a dataview js inline query from another note which also includes the replaceAll function so I get the different values on separate rows. Anyone know how I could achieve this?

Thanks!

You could try using the dv.page() method;

`$= dv.page("Reference Index").file.outlinks.join("<br>")`

hmm, tried many different combinations using the dv.page() but as I just started with javascript I can’t quite get it to work.

Lets say there is a note called “test1” which consists of:

---
mykey: verdi1-1, verdi1-2, verdi1-3 
---

How can I recall “mykey” values from another note using dataview js (`$= dv. etc)?

`$= dv.page("test1").mykey.replaceAll(", ", "<br>")`

If you’d like to treat the values as a list, I recommend you format your yaml like so:

---
mykey: 
- verdi1-1
- verdi1-2
- verdi1-3 
---

or

---
mykey: [verdi1-1, verdi1-2, verdi1-3]
---

…it makes it simpler to query the values with Dataview:

`$= dv.page("test1").mykey.join("<br>")`

Thank you!!!
This solved it!!

1 Like

It’s solved… :slight_smile:

My contribute is only to point the solution in DQL (in the case, you’re not “forced” to use dataviewjs).


For format as a single string:

---
mykey: verdi1-1, verdi1-2, verdi1-3 
---

you can use

`=replace([[My Note]].mykey, ", ", "<br>")`

For format as list

---
mykey: 
- verdi1-1
- verdi1-2
- verdi1-3 
---

you can use

`=join([[My Note]].mykey, "<br>")`
1 Like

Wow, thank you @mnvwvnm !
this is very useful! I will save it in my “code” note for later!
Just recently started with obsidian and planning to build my own personal reference system for medical litterature and the possibilities in obsidian are just endless with js code (and DQL) :wink:

Hi again,

So the original problem is solved, but I have a follow-up question.

As suggested by @Craig, frontmatter variables can be changes with the dataview inline js:

`$= dv.page("NoteName").mykey.replaceAll("old", "new")`

However, this is not working if I try to change something else than frontmatter info. For instance if I try to use the replaceAll function on inlinks I get an error (says replaceAll is not a function):

`$= dv.page("NoteName").file.inlinks.replaceAll("old", "new")`

Is there a way I can use replaceAll or other function to change the characters in inlinks? In this case all my inlinks starts with a “@”, which I would like to remove.

Main problem: links aren’t strings!
If you want a solution in dql I can provide it.

`=map([[NoteName]].file.inlinks, (i) => link(i, replace(i.file.name, "old", "new")))`

In dvjs I think it’s a little different because we can’t go “through” the link… we need to “build” the new link.

`$= dv.page("NoteName").file.inlinks.map(i => dv.fileLink(i.path, false, dv.page(i.path).file.name.replaceAll("old", "new")))`

But maybe someone with regex knowledge can solve it in another way.

Perfect!! Thank you!

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