Hey Craig - very much appreciate the response. Still not working. Maybe my writing it out to you will help me (or you, more likely) solve it… My steps:
Tested a dataview table in a note - to make sure it works.
Table zColor, zShape
From ""
Where file.link = [[]]
Used Visual Studio Code to create a .js file in my ‘035 Scripts’ folder called Case004a. Following is full script.
dv.execute(`
Table zColor, zShape
From “”
Where file.link = [[]]
`);
*Note - I tried with and without ```dataview intro/outro
Included the following in an obsidian note:
dv.view("/035 Scripts/Case004a.js");
*Note: I tried with and without the ‘.js’ at the end
The error (when excluding .js) is:
Evaluation Error: SyntaxError: missing ) after argument list
at new Function ()
at DataviewInlineApi.view (plugin:dataview:19602:24)
at async DataviewJSRenderer.render (plugin:dataview:19705:13)
OK - if you’ve read this far, I appreciate your patience. Perhaps I’m being an idiot and missing something silly. Of course, any ideas are greatly appreciated…thanks, Craig.
Just a question: why would you want to embed your DQL queries? Just in order to avoid having to type often used queries anew each time you want to make use of it?
I think you’re really close! I’m not entirely sure what we’re doing differently, so I set up a little mini-vault with two files in it to see if I could re-create your error. It seems to be working for me, so I’m including a screenshot of my setup as well as a zip of the vault (if the forum lets me) so that maybe you can look at it and see where the differences are.
P.S. I noticed an issue with your js file – the quotes on your From statement are curly quotes, not regular quotes. That won’t work with Dataview. That might just be a copy-paste issue into the forum, but I thought I’d mention it in case your computer is getting too helpful.
In my use case, I have a team of people that are assigned to different projects. When I’m meeting with a particular person, it’s helpful for me to have a query on their contact page that shows all the projects assigned to them, the next action for each project, and so forth. The query is somewhat complex, using FLATTEN and GROUP BY to display the projects in a way that makes sense for our org.
And as we adapt our processes and workflows to new requirements, I need to make adjustments to the query to show the information I want to have at hand during a meeting. If there was a copy of the query on each contact page, I would have to remember to update each copy of the query for every contact page every time I need to make a change to the query. That’s very tedious and error-prone for someone with a brain like mine.
Instead, I want to maintain this complex query in one place. That way, when I make changes to it, every contact page automatically shows the updated query without any need to edit the contact pages. I hope that helps!
Craig
P.S. You asked why I can’t use templates. If I include the complex query in a template, I get it on each new page, but I still have the problem of having to edit each page every time I want to update the query.
Here’s another option that lets your reusable query live in a Markdown file, which should only contain your DQL query with no extra JavaScript wrapper and no code block wrapper.
I was thinking about the execute / load suggestion @orand mentioned, because I really like the option to be able to see it as a md-file.
Is that also possible with the dv.view-option?
I’m the new guy around here, and I’ve got some tips and questions related to this topic. Which might be off target completely, but here goes.
First of all, using the Plaintext plugin, and adding js as an extension, one is able to edit javascript within Obsidian, albeit without some of the bells and whistles of a more dedicated code editor, like Visual Code 2. Only downfall so far, is that to create the file initially you either need to create an ordinary note within Obsidian, and rename it from .md to .js outside of Obsidian. Or you’ll create the file outside of Obsidian.
Lastly, is there a particular reason you’re using dv.execute() instead of dv.query()? The latter seems to have an option to pass a file, pretending to be this, so that it can mimic being on the original note even more than what dv.execute() seems to do. It would also allow for even more post-processing, and handling after query execution if one would want that. See Dataview: Function to get length of unique values OR using nested queries - #2 by holroy, for an example where I post process a DQL query to show summary of the summaries.
Wonderful work here. I stumbled across this completely accidentally today and it solved a problem I knew that I had before I began looking for a solution.
I’m developing a template that shows movies watched, books read each month. Across many years, there are many files I need to create. The problem with normal templating is should I make a change, I need to update many files.
This solves that perfectly, One .js file linked to all the others.
Hi @anon63144152, great question. I’m generally a fan of more atomic notes, so I would probably keep it to one file per query and then refer to them individually.
Of course, if the two queries depend on each other, or would always be together, then it might make sense to keep them in the same file.
I think I am going to have to go for one query in each JS file as I can’t get two queries in the same file to run. I would ideally like to add some inline JS snippets in the JS file as well but not been able to make those work either. Baby steps. Lots of reading to do.
But brilliant idea. Loving the paths it is taking my mind along.