Is there a way to create metadata values with a dataview result

What I’m trying to do

I am trying to add the result of this dataview query which is 2 to the YAML metadata.

teamMembersCount: (The result should go here)


LIST WITHOUT ID length(rows) FROM "Players" WHERE contains(Team, group by Team

I have tried to use dataviewjs but could figure it out and google didn’t come with a result.

There are at least two options, and that is to trigger the meta-edit plugin and do the update that way, or to use the obsidian API and trigger the process frontmatter function and update out that way.

Both do require a little coding, but examples can be found within the field.

Here is one of my posts where I’ve used app.FileManager.processfrontmatter() could possibly help you a little bit of the way. Do recognisethat when changing the current file you might need to use setTimeout() with a proper delay to counter some ravd conditions.

Can’t seem the get this to work.

No solution has been found as of today.

Still, no solution now trying to do stuff with the plugin metadata menu. aswell

You’ve been given a link to a setup which do just what you ask about. Still you keep bumping this thread, which by the way is against the community guidelines of I’m not mistaken, not providing any new information as to why the proposed solution doesn’t work for you, nor anything about wussy you’ve actually tried (working or not).

Due to this I’m tapping out, but I do wish you the best of luck trying to figure this out.

I am currenly testing it in just datviewjs

I currently have this code:

const currentFileName = dv.current();
const rosterPages = dv.pages('"Roster"');
const count = rosterPages.filter(p => {
  const faction = p.frontmatter && p.frontmatter.faction;
  if (typeof faction === 'string') {
    return faction.includes("[[" + currentFileName + "]]");
  if (Array.isArray(faction)) {
    return faction.some(f => f.includes("[[" + currentFileName + "]]"));
  return false;



It result in the console as

Wulf’s Den

VM420:17 Proxy(DataArrayImpl) {values: Array(12), settings: {…}, length: 12, defaultComparator: ƒ}

VM420:18 0

So I need a solution to this and then make it so works for the metadata menu plugin (Which i am currently using)

This line doesn’t return the value of the faction, if I’m not mistaken it’ll just return a boolean. Have you tested this?

Are you notes stored within the Roster folder, and do you see the expected files from this folder when doing console logging?

I did not realize the code.
How would I fix that? I imagine p.fontmatter.faction.value??? but that isn’t the solution

The pages I want to check are indeed in the Roster folder. the number of pages is correct as there are 12 notes in the roster folder.
The result is correct as seen in the VM420:17 Proxy(DataArrayImpl) {values: Array(12), settings: {…}, length: 12, defaultComparator: ƒ}

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