Is there a way to run a script from an inline button in dataview query

I used this code to update YAML field with an inline button. My question is can I run a js script from an inline button. If so can you share a sample code.

// This is what I am currently doing
createButton({app, el: this.container, args: {name: “+”, color: “green”}, clickOverride: {click: update, params: [‘A1’, (t.A1 + 1), t.file.path] }})

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks) is properly shown.

The clickOverride parameter is calling the update function of metaedit, if I’m not mistaken. You could easily define a similar function, and do whatever you’d like in that function.

Your code is currently:

createButton({
  app, 
  el: this.container, 
  args: {
    name: “+”,
    color: “green”}, 
    clickOverride: {
      click: update, 
      params: [‘A1’, (t.A1 + 1), t.file.path] 
    }
  })

Which will end in a call like: update('A1', (t.A1 + 1), t.file.path)

Here is similar (but untested code):

function myUpdate(a, b, c) {
  update(a, b, c)
}

createButton({
  app, 
  el: this.container, 
  args: {
    name: “+”,
    color: “green”}, 
    clickOverride: {
      click: myUpdate, 
      params: [‘A1’, (t.A1 + 1), t.file.path] 
    }
  })

This should do the same, but uses another function, myUpdate. And this should then be expandable to be able to do extra stuff or other stuff if you’re so inclined.

2 Likes

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