Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can we run a script for a button click event

Pradeep A
Contributor
July 6, 2021

Hi I just created a button using Script fragment. I want to run a certain script on clicking the button is it possible?

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2021

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.

Of course, you could always create your own javascript to react to the button click and call your rest endpoint.

Pradeep A
Contributor
July 6, 2021

Hey thanks for your answer, but I'm new to jira and script runner. Can you please explain how to link the button to an endpoint and run the code?

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2021
Pradeep A
Contributor
July 7, 2021

Thanks for your help

Pradeep A
Contributor
July 7, 2021

I came across another scenario. Will I be able to access the input I give in the text box while running the script?

 

For example: let's say I have a text box and a button. I need to display the information entered into the text box while clicking the button.

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2021

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.

Your dialog will include the form and input field you want the users to fill in. The form button will have to have some javascript to call your rest endpoint and include the user's input.

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.

Suggest an answer

Log in or Sign up to answer