Forums

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

ScriptRunner how to add a comment by status change of an Issue

sue molly
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 24, 2020

Hello Community,

I am trying to figure out how I can add a comment if the Status of an Issue changes 

I would like to add a functionality such that when a certain event occurs, the status of an issue should automatically changed from "Open" to "In progress" if a comment will be added as example 

 

I know it is not finished but I tried accomplishing this with the following code 

if(issue.getIssueType().name=="Task"){

MutableIssue epic = issue
epic.setStatusId("2"); //Read that 2 meant status = "Done"

}

Could someone provide me with guidance regarding this issue.

I appreciate all the help!

Regrads cennet 

2 answers

0 votes
Bert Dombrecht
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.
September 24, 2020

Hi,

I'm a bit confused.

Do you want a transition to occur if a comment is added?
Or do you want a comment to be added if a transition occurs?

I'm assuming the first.
We have implemented this with a Script Listener.

Create a Script Listener, select the project(s) to which it applies and select 'Issue Commented' as Event.

Then the script goes:

// Imports
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import com.atlassian.jira.issue.Issue;

// Variables
Issue issue = event.issue;
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser();
def transitionId = 33; // the transion id you need to have triggered

def issueService = ComponentAccessor.getIssueService();
def issueInputParameters = new IssueInputParametersImpl();
def transitionValidationResult = issueService.validateTransition(user, issue.id, transitionId, issueInputParameters);

// Function
if (transitionValidationResult.isValid()) {
issueService.transition(user, transitionValidationResult);
}

In our implementation we added an if statement in front of the function that filters out certain users and makes sure the issue is in a specific status to start with.

0 votes
Ravi Sagar _Sparxsys_
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.
September 24, 2020

Hi @sue molly 

Status is a not a field that you can set. You need to transition the issue. I wrote a script to transition the issue with some instructions. Take a look.

Adding a comment is an event which you can capture and do something like transitioning an issue (changing status). You can listen to these events by creating a Script Listener. 

So create a listener using "Issue Commented" event and write a custom script to transition the issue.

I hope it helps.

Ravi

Suggest an answer

Log in or Sign up to answer