Help needed with dataview JS table

Things I have tried

What I’m trying to do

I am working on my book library. Sometimes, I have to update my template which then requires me to go back to every book I have added and individually change each item. I was previously using Notion where if I changed my property end-date to completed-date it updates if across all my books files. Or I could move the author to show up before my date. Is there any way to do something like this in Obsidian?

I am trying to make a dataview JS table of my books read. The following table works , but gets all of my books.
dv.table(["Cover","Title", "Author", "Date", "Series", "Rating____", ],
dv.pages("#bookhistorical")
    .sort(p.finished)
    .map(p => ["![Cover|90](" + p.cover + ")",
		p.file.link,
		p.Author, 
		p.finished,	   
		p["Series"] ? p["Series"] + " #" + p["number-in-series"] : "N/A",
	    p.Rating 
															  
			]) 
)

But when I try to configure it to only show my books that have a bookprogress that equals 100 it breaks. I have read through all of the dataview information to try and make it work, but with no luck. I’ve tried contains, filter, etc. Is there anyone that can help me figure out what I am doing wrong? Here is the new query.

dv.table(["Cover","Title", "Author", "Date", "Series", "Rating____", ],
dv.pages("#bookhistorical").where(p => p["bookprogress"] == 100));
    .sort(p.finished)
    .map(p => ["![Cover|90](" + p.cover + ")",
		p.file.link,
		p.Author, 
		p.finished,	   
		p["Series"] ? p["Series"] + " #" + p["number-in-series"] : "N/A",
	    p.Rating 
															  
			]) 
)

Thanks

Hi.
JS is not my ground… And, if I can ask, why you choose JS? You have js knowledge; it’s a more easy language to learn; you need some “extra” functions only available in js (in you queries above all functions are available in DQL); etc.
(you don’t need to answer) :slight_smile:
I’m not sure, but try this: replace where(p => p["bookprogress"] == 100) by where(p => p.bookprogress && p.bookprogress == 100).

EDIT 1: seems that you have other “errors” in your code.
If you need a DQL query…

EDIT 2: Try now

dv.table(["Cover","Title", "Author", "Date", "Series", "Rating____"],
dv.pages("#bookhistorical").where(p => p.bookprogress == 100)
    .sort(p => p.finished)
    .map(p => ["![Cover|90](" + p.cover + ")",
		p.file.link,
		p.Author, 
		p.finished,	   
		p["Series"] ? p["Series"] + " #" + p["number-in-series"] : "N/A",
	    p.Rating 
															  
			]) 
)

I am happy to answer your question. There are two main reasons I have been using JS. One is that I want to automate as much as I can. I came from Notion where I could use formulas and filters to get what I was looking for, but I didn’t like that it was on a server because it often was very slow and I didn’t like not having access to my files.

Second because I am just learning how to use JS on my own I have been trying different things, each problem I solve helps me learn and better problem solve in the future. Unfortunately, I also don’t know anything about DQL queries which is why I don’t use them. Where would I go to learn about it?

I tried the edit and got the following:

Evaluation Error: SyntaxError: Unexpected end of input

The other option for doing this could be any book that has a date in finished: instead of bookprogress: 100. Would that be easier?

Strange… works on my side.
the field bookprogress exists? (only with single values?)

About JS, I asked because I don’t know js and I’m curious about the reasons to start with it and not with dql. But you’re right: if you need to start with one…

(about book progress vs finish date) I’m not sure, but I think it’s not so easy to work with dates…

That’s what I thought too about the dates

Ok. so i just realized that I had too many ``` which was messing it up, so I got rid of those and now my error is saying
Evaluation Error: ReferenceError: p is not defined

maybe you don’t copy all my code. in your previous code you have that error in sort. because that I change .sort(p.finished) to .sort(p => p.finished)

That worked! Thanks so much!

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