scriptrunner how to get user input for web item

Noam Twena May 13, 2023

I already created a web item button.

I already created a REST endpoint to make my groovy code work when I click the button.

 

What I need is  - get user input for my groovy code. (I guess it is done with JS in web resources but I'm not sure how)

Is this possible?

 

 

 

2 answers

0 votes
Graham Twine
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.
May 14, 2023

Hello @Noam Twena

May I please firstly confirm by web item you do mean this?

Further more, what is "Your Groovy Code"?

Is it a Scriptrunner REST endpoint that accepts some query parameters?

What section have you placed this on?

What is the button? By this I mean is it a <button /> or is it an anchor with css button classes?

Is the file that contains the button a velocity template?

 

If I am understanding you correctly then may I propose the following.

1. If you are using a button, it may be easier to use an anchor with an Ajax call to your custom rest endpoint. If you use a button then the href property will not do strange things when clicked. Consider which suites your use case better.

2. Bind a javascript function that contains the Ajax call in the On init function(Document ready) is the button in the DOM when the page loads?

 

What happens if I spam click the button? (Debounce / disable / remove) the element on click and a successful Ajax response.

 

What is the response going to do to the page? Add some stuff / nothing only a 200 response is needed to confirm a successful call.

 

Have you looked at AUI, this is useful for DC and server as well.

If you use velocity will the file just contain the javascript?

If not it will need to be registered as a downloadable resource in the plugin.xml

Is this even a custom plugin?

 

Graham

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 14, 2023

Hi @Noam Twena  and welcome,

in order to retrieve information about logged in user you could try the following code :

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

Hope this helps,

Fabio

Suggest an answer

Log in or Sign up to answer