Dataview values to YAML properties with Meta Bind plugin?

Hi all! First post here. I’ve tried to search for something similar but haven’t found an answer to my problem, or haven’t been able to identify it with my limited knowledge :sweat_smile:, sorry if this has been solved elsewhere. Any help is appreciated.

What I’m trying to do

I’m trying to build a base with files for game notes (Fantasy Life 3ds). I wanted to have one note for each ‘life’ (profession), where I store all the quests that need to be completed to advance in that life. I thought it would be possible to use a Dataview query to update how many quests I’ve completed once I’ve checked them off in the note, and then sync the values calculated with Dataview for overall progress and some other stats to the YAML properties so that I could display them in the base itself using the Card view.

Things I have tried

  1. Used this Dataview query (parts of it are in Spanish because that’s the language I’m playing the game in. Also, I used Gemini to help since I’m at a loss on how to achieve complex stuff with Dataview yet - I know this isn’t ideal):
const page = dv.current();
const tasks = page.file.tasks;
const completedTasks = tasks.filter(t => t.completed);
const totalTasks = tasks.length;

let starsEarned = 0;
completedTasks.forEach(task => {
    const match = task.text.match(/(\d+)\s*Estrellas/);
    if (match) {
        starsEarned += parseInt(match[1]);
    }
});

const rankThresholds = [
    { name: "Novato", stars: 100 },
    { name: "Aprendiz", stars: 500 },
    { name: "Versado", stars: 1200 },
    { name: "Experto", stars: 4000 },
    { name: "Maestro", stars: 8000 },
    { name: "Héroe", stars: 12000 }
];

let nextRank = "¡Rango Máximo!";
let starsToNext = 0;
let currentRankName = "Principiante";

for (let rank of rankThresholds) {
    if (starsEarned >= rank.stars) {
        currentRankName = rank.name;
    } else if (starsToNext === 0) {
        nextRank = rank.name;
        starsToNext = rank.stars - starsEarned;
    }
}

const progressPercent = totalTasks > 0 ? Math.round((completedTasks.length / totalTasks) * 100) : 0;

const progressBar = "█".repeat(Math.floor(progressPercent / 5)) + "░".repeat(20 - Math.floor(progressPercent / 5));

dv.header(3, "Rango Actual: " + currentRankName);
dv.paragraph(`**Progreso de Misiones:** ${completedTasks.length}/${totalTasks} (${progressPercent}%)`);
dv.paragraph(`\`${progressBar}\` ${progressPercent}%`);
dv.paragraph(`**Estrellas Ganadas:** ${starsEarned}`);
dv.paragraph(`**Siguiente Rango:** ${nextRank}`);
dv.paragraph(`**Estrellas Necesarias:** ${starsToNext > 0 ? starsToNext + " ⭐" : "¡Completado!"}`);

const fields = [
    `progress:: ${progressPercent}%`,
    `current_stars:: ${starsEarned}`,
    `stars_to_next:: ${starsToNext}`,
    `current_rank:: ${currentRankName}`
].join(' '); // Joins with a space

dv.span(fields).style.display = 'none';
  1. Enabled JavaScript queries in the Dataview settings
  2. Enabled JavaScript in the Meta Bind settings
  3. Disabled code restrictions in the Meta Bind settings
  4. Cleaned up my YAML properties in Source Code to ensure there were no previous values conflicting with the code

I haven’t been able to get it to work yet, and since I’m a beginner, I don’t know what to do to fix it. Anyone have any idea? Thanks in advance!

I’m not clear which part you’re asking about. Taking it one step at at time:

  1. Does your DataviewJS query return the results you want?
    If no, then first focus on fixing that or finding another way to get your results.
    If yes, then…
  2. Is MetaBind putting the result in your note’s properties?
    If no, then instead of troubleshooting it, perhaps consider using the community plugin called “Dataview (to) Properties”, which sounds like it more directly does what you want: obsidian://show-plugin?id=dataview-properties / obsidian-dataview-properties on GitHub.
    If yes, then…
  3. Is your Base displaying the properties you want?
    If no, then can you say more about your base set up (your formulas and filters), your note YAML, and what part isn’t working?
    If yes, then… forum malfunctioning, where am I? Let me out of this place :technologist:.

Hi! Sorry for the late reply. And yes, you’re right, I wasn’t specific at all in my first post! I couldn’t get the auto-syncing between properties and the Dataview values to work – either nothing showed up in the property fields at all, or I got the string as-is, without it rendering into the actual data.

I didn’t know about the “Dataview (to) Properties” plugin, so thank you for the recommendation! I tried to get it to work but I couldn’t manage to, so in the end I went with Templater and added a button that triggers a template to add the data to the properties. It’s not automatic and I need two separate notes, but it works!

Thank you for your help :slight_smile: