How to add a button that executes a transition on another ticket?

Jon Schewe April 12, 2021

I have Jira with ScriptRunner.

I have a Request issue type and an Approval issue type. Multiple approval issues are related to a request issue. This represents multiple approvals for the request.

The user for each approval could click on the linked approval issue and then click the appropriate transition which prompts for a comment. 

However I'd like to make it a little easier for users that aren't used to Jira. I'd like there to be "Approve" and "Reject" buttons at the top of the request issue type that will execute the appropriate transition on the related issue AND prompt the user for the comment like they normally would if following the transition manually.

I have figured out how to get ScriptRunner to add an additional button to the top of the Jira view screen. I can also make this button conditionally visible based on the logged in user and the linked approval issues.

What I haven't figured out is if there is a way have that button execute the transition in the related ticket and prompt for the comment. I did find that if I paste the link for the button on the approval issue into my browser window I can get the comment dialog to show up. However putting that link into a web panel that doesn't appear to work.

Anyone have ideas on how to execute this transition?

Alternatively I could prompt for the comment in a dialog that comes up from the custom button and then execute the transition on the back end. However I haven't figured out how to add an input field to the custom dialog and capture it's output yet.

 

2 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 19, 2021

Why don't you build that into the Request workflow rather than trying to use custom buttons?

Create global transitions where the target status is the current status (so your request issue won't actually change).

  • Add a transition screen with only the comment
  • The workflow condition can determine when to show or hide the approve/reject button.
  • The validator can ensure the comment is entered.
  • A custom post function can look for the linked Approval issue and apply the desired transition.

You can have the comment entered by the user in the form replicated on the approval ticket. And if having the comment on both issue is a problem for you, you might be able to delete the comment either during or after the transition (not sure about this one).

Jon Schewe April 19, 2021

I was trying to avoid the extra comments, but maybe this is the best option.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 19, 2021

Yeah, building a whole custom form to avoid an extra comment seems overkill.

Another option is to use a custom comment field on your request issue type that is only visible in the approve/reject transition. This would be easier to clear out the value with minimal history (or perhaps even before it is stored by the post function).

0 votes
Payne
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.
April 12, 2021

I have done something like this. Below are sections of my script that illustrate how I went about this. Hope you find it useful.

//The method that actually performs the transition
def runApproveTransition(IssueService issueService,ApplicationUser jiraAdminUser,Long subtaskId,int transitionApproveSubtask)
{
IssueInputParameters issueIP = issueService.newIssueInputParameters()
TransitionOptions transitionOptions = new TransitionOptions.Builder().skipConditions().skipPermissions().skipValidators().build()
TransitionValidationResult validationResult = issueService.validateTransition(jiraAdminUser, subtaskId, transitionApproveSubtask, issueIP, transitionOptions)
issueService.transition(jiraAdminUser, validationResult)
}

//A call to that method
runApproveTransition(issueService,jiraAdminUser,subtaskCreated.id,transitionApproveSubtask)

//Definitions of the passed variables
IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser jiraAdminUser = ComponentAccessor.getUserManager().getUserByName("jiraadmin")
subtaskCreated // is the Issue that we wish to transtion
final int transitionApproveSubtask = 41

And, of course, you'll need a few imports. Hopefully this will get you headed in the right direction.

Jon Schewe April 12, 2021

This part I already know how to do. What I don't know how to do is prompt the user for the comment that I want them to enter on the transition that I am executing programatically. That or redirect the user's browser as if they had clicked the transition button on the approval ticket.

Suggest an answer

Log in or Sign up to answer