Set Variable using YAML Value

What I’m trying to do

Within a table generated listing notes in a folder, I am trying to set a variable in a button - ${area} with the value from YAML “area:” for each note in the table.

The purpose: to display a list of notes in a table, select the metadata “area” for each note and then click the button to move the note to the proper folder based on that value.

const {fieldModifier: f} =["metadata-menu"].api;

dv.table(["Name", "Area", "Type", "Timing", ""],
    dv.pages('"_inbox/Unprocessed Notes"')
    .map(p => {
        const btn = this.container.createEl('button', {"text": "Move to Area"});
        btn.addEventListener('click', async () => {

            const area = // <- this is the varible I am looking to set to the value "area" for the note 
            if (!area) {
                alert("Please set area");
            const destPath = `2. Areas/${area}/${}.md`;
            //await`2. Areas/${area}`);
            await, destPath);
            await dv.refresh();
        return [
            f(dv, p, "area"),
            f(dv, p, "note_type"),
            f(dv, p, "timing"),

Things I have tried

The script below is working IF I hard code the value of ${area}. I can’t figure out how to do that programmatically.

I don’t know JavaScript, I’ve just been pulling this together from resources I find - and throwing things at the wall to see what sticks.

Any suggestions on how to get this done?

You’re using within that script, are you looking for the similar usage of p.area ? Is that it?

If not, I’m not grasping where you want to pull the area value from, or how you want to set it. And do you expect for it to be changed within the file, or do you just want to read it out of the file?

After doing a little testing, and reading a little more carefully I see the connection to the metadata-menu plugin, which allows for modifications within the table. So that answer my questions from before here.

In addition, I can now confirm that using p.area does indeed pull out the current value of the area, so that when I hit the button (after it has refreshed at least), it’ll use the new value.

However, I’m not having a dv.refresh() in my dataview version, so I had to comment out that call. It still seems to work, though.

1 Like

Wow. Amazingly more simple that I was thinking.
Thank you!

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