Yes, your button will have to be linked to a scriptrunner custom REST endpoint and that endpoint will run your code.
The easiest option is to select "run code and show a flag" in your web item fragment, then your rest endpoint just has to return a flag map to show the result of running your script.
If you're looking to provide input to your REST endpoint and your script, then you will have to follow some of the instructions in that adaptavist documentation page under Dialogs (Advanced) section.
But if you are dealing with a jira issue, it might be easier to have a transition (from any status to itself) and a transition screen provide you the form and the post function to execute your script.
Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events