Limit the output of metadata menu

What I’m trying to do

Hello community,

referring to this topic:

I just want to limit the output of the dataviewjs output.

Things I have tried

my customized code looks like this:

const {fieldModifier: f} =
	  this.app.plugins.plugins["metadata-menu"].api;
dv.table(['Task', 'status', 'beg', 'Z', 'due'],
	await Promise.all(dv.pages('"Projekte"')
		.where(p => (p.projekt == dv.current().projekt))
		.where(p => (p.objekttype == "Aktion"))
		.limit(10)
		
		.map(async p => [
			p.file.link,
			await f(dv, p, "state", {options: {alwaysOn: true}}),
			await f(dv, p, "dat-beg", {options: {alwaysOn: true}}),
			await f(dv, p, "zeit-beg", {options: {alwaysOn: true}}),
			await f(dv, p, "due-date", {options: {alwaysOn: true}})
		]))
		
		
		)

All my tasks have the frontmatter value:
procedure: Aktion

and belong to a project which is set as i.e.:

project: [[Projekt so and so]]

But the query of dataviewjs from above gives “no results” back.
I think it has to be something to do with the where-clause

.where(p => (p.projekt == dv.current().projekt))

because when I remove this line, I get results, which I can edit (metadata Menu).
But I need only the results of the current File (project).
I also tried it with the &&-Operator - also negative.

I tried, too:
.where(p => (p.projekt == this.projekt)) - negative.

How do I narrow down the output for only the current file (project)?

I hope, datacore is coming soon to daylight, so this will be less complicate (obsolet)

thanks in advantage

If this is what’s listed in your frontmatter, then your issue might simply be that this is the definition of an array with one element which is an array with the element “Projekt so and so”. In particular, this is not a link to the “Projekt so and so” file.

So for starters you need to build the query listing all the files related to your current project (aka “dv.current().projekt”).

This could be as simple as changing all your projekt definitions to be of the form: projekt: "[[Projekt so and so]]", which is a better way to define a “link” within the frontmatter.

Another “simple” alternative would be to move the definition of projekt out of the frontmatter and into the body of the text, and thusly become projekt: [[Projekt so and so]]. This will also have other benefits such a inlinks and backlinks will start working, and renaming of projects will propagate throughout your vault.

Please report back, if either of these are enough, or whether you need to do more thorough debugging of your script using the javascript console accessible through the Developer Tools menu. (And in this case, please note if you’ve ever used the console before)

thank you for your reply.
I moved it in the body of more then 10 notes via

projekt:: [[Projekt so and so]]

there has to be something to spit out

output:

console:

To a deeper dive into debugging, I would use temporary variables, and console.log() calls within the query. And the natural first step since you state that your query works if you don’t do the where project clause, is to examine what happens in that clause.

So I would most likely do something like this:

```dataviewjs
console.log("\n\nNew run, where projekt is:" , dv.current().projekt)

const result = await dv.pages('"Projekte"')
  .where(p => {
    console.log("  p.projekt:", p.projekt)
    return (p.projekt == dv.current().projekt)
  })
  .where(p => {
    console.log("    p.objekttype: ", p.objekttype)
    return (p.objekttype == "Aktion")
   })
  .limit(10)

console.log(result)
```

This query (if I’ve not made any major typos), should show the values it compares, and hopefully give you some hints related to why it doesn’t return the values you expect it to. From there on, you just need to keep tweaking this until the result output is what you expect it to be, and then you can extend it by adding the mapping and do something like:

```dataviewjs
const {fieldModifier: f} =
	  this.app.plugins.plugins["metadata-menu"].api;

... correct query to be inserted here ...

if (result.successful ) {
  dv.table(['Task', 'status', 'beg', 'Z', 'due'],
     result.values
       .map(async p => [
            p.file.link,
			await f(dv, p, "state", {options: {alwaysOn: true}}),
			await f(dv, p, "dat-beg", {options: {alwaysOn: true}}),
			await f(dv, p, "zeit-beg", {options: {alwaysOn: true}}),
			await f(dv, p, "due-date", {options: {alwaysOn: true}})
		]))
} else
  dv.paragraph("~~~~\n" + result.error + "\n~~~~")
```

Or similar. Last part totally untested… :slight_smile:

Well, uhm…
I pasted your code, but I have absolutely no clue, what I’m doing… :smile:
I checked the console… hold tight!

New run, where projekt is: Link {path: 'Museum/Projekte/Allg Homepage 2023.md', type: 'file', subpath: undefined, display: undefined, embed: false}display: undefinedembed: falsepath: "Museum/Projekte/Allg Homepage 2023.md"subpath: undefinedtype: "file"[[Prototype]]: Objectconstructor: class Linkequals: ƒ equals(other)fileName: ƒ fileName()fromEmbed: ƒ fromEmbed()markdown: ƒ markdown()obsidianLink: ƒ obsidianLink()toEmbed: ƒ toEmbed()toFile: ƒ toFile()toObject: ƒ toObject()toString: ƒ toString()withDisplay: ƒ withDisplay(display)withHeader: ƒ withHeader(header)withPath: ƒ withPath(path)[[Prototype]]: Object
VM366:14 Proxy {values: Array(0), settings: {…}, length: 0, defaultComparator: ƒ}[[Handler]]: Objectget: ƒ (target, prop, reciever)length: 3name: "get"prototype: constructor: ƒ (target, prop, reciever)[[Prototype]]: Objectarguments: (...)caller: (...)[[FunctionLocation]]: plugin:dataview:8283[[Prototype]]: ƒ ()apply: ƒ apply()arguments: (...)bind: ƒ bind()call: ƒ call()caller: (...)constructor: ƒ Function()length: 0name: ""toString: ƒ toString()Symbol(Symbol.hasInstance): ƒ [Symbol.hasInstance]()get arguments: ƒ ()set arguments: ƒ ()get caller: ƒ ()set caller: ƒ ()[[FunctionLocation]]: ​[[Prototype]]: Object[[Scopes]]: Scopes[0][[Scopes]]: Scopes[3]0: Closure (anonymous) {listId: ƒ, null_to_empty: ƒ, untruncateYear: ƒ, stringifyTokens: ƒ, parseCsv: ƒ, …}1: Script {Pos: ƒ}Pos: ƒ Pos(line, ch, sticky)[[Prototype]]: Object2: Global {0: Window, window: global, self: global, document: document, name: '', location: Location, …}[[Prototype]]: Object[[Target]]: DataArrayImpldefaultComparator: ƒ compareValue(val1, val2, linkNormalizer)length: 0settings: allowHtml: truedataviewJsKeyword: "dataviewjs"defaultDateFormat: "MMMM dd, yyyy"defaultDateTimeFormat: "h:mm a - MMMM dd, yyyy"enableDataviewJs: trueenableInlineDataview: trueenableInlineDataviewJs: trueinlineJsQueryPrefix: "$="inlineQueriesInCodeblocks: trueinlineQueryPrefix: "="maxRecursiveRenderDepth: 4prettyRenderInlineFields: truerecursiveSubTaskCompletion: falserefreshEnabled: truerefreshInterval: 2500renderNullAs: "\\-"showResultCount: truetableGroupColumnName: "Group"tableIdColumnName: "File"taskCompletionDateFormat: "yyyy-MM-dd"taskCompletionText: "completion"taskCompletionTracking: falsetaskCompletionUseEmojiShorthand: falsewarnOnEmptyResult: true[[Prototype]]: Objectvalues: Array(0)length: 0[[Prototype]]: Array(0)[[Prototype]]: Object[[IsRevoked]]: false
[Violation] Forced reflow while executing JavaScript took <N>ms

am just as stupid as before :man_shrugging:
sorry.

1 Like

Isn’t “Projekte” a root folder in your vault? Should it be “Museum/Projekte” in the call to dv.pages?

I tried ‘“Museum/Projekte”’ also ‘“/Museum/Projekte”’, all lead to empty results…
in other queries the dv.pages('"Museum/Projekte"') works fine.

And you don’t get any extra output in the console?

these are all entries i got:

This doesn’t make sense, you should get more output if the folder is correct and works in other contexts. There should be some lines with the “p.projekt” output…

One possibility for further debug is opening up removing the folder, but then you should add a filter related to the projekt field…

I have adjusted it like this:

const {fieldModifier: f} =
	  this.app.plugins.plugins["metadata-menu"].api;
dv.table(['Task', 'status', 'beg', 'Z', 'due'],
	await Promise.all(dv.pages('"Museum/Projekte"')
		.where(p => (p.objekttype == "Aktion"))	
		.filter(p => (p.projekt == dv.current().projekt))	
		.limit(10)
		
		.map(async p => [
			p.file.link,
			await f(dv, p, "state", {options: {alwaysOn: true}}),
			await f(dv, p, "dat-beg", {options: {alwaysOn: true}}),
			await f(dv, p, "zeit-beg", {options: {alwaysOn: true}}),
			await f(dv, p, "due-date", {options: {alwaysOn: true}})
		]))
)

empty output.

And none of the output I suggested? Then how do you plan to figure out what’s wrong?!

Well, good luck with you endeavors… I’m out…

even with put on everything (clearing the path out of dv.pages)

...
dv.table(['Task', 'status', 'beg', 'Z', 'due'],
	await Promise.all(dv.pages()
		.where(p => (p.objekttype == "Aktion"))	
		.filter(p => (p.projekt == dv.current().projekt))	
		.limit(10)
...

well, nevertheless thank you for your efforts…

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