How to change issue data with ScriptRunner groovy scripts

Deleted user March 10, 2015

I made a .groovy file with which I want to change the issue summary on comment event. If the comment contains some string 'x' and that string 'x' isn't in the summary of issue, then add it to the beggining of issue summary:

Here is the code for doing this, but it doesn't seem to work, what can be the cause? I put the script in /WEB-INF/classes and in the log file isn't anything recorded.

Can I change any issue data with .groovy scripts (the file is groovy extension, but the code syntax is in JAVA)?

I made before custom listenters like this, but it was just fetching the data, it wasn't writting anything to database.

public class AddAutoIssueKeyToIssueSummary extends AbstractIssueEventListener implements IssueEventListener {

protected void addIssueKeyToIssueSummary(com.atlassian.jira.event.issue.IssueEvent event){

int stringIndex;
String issueKeyString = "HHOO-";
String temp="";

com.atlassian.jira.issue.MutableIssue eventIssue = event.getIssue();
if(!eventIssue.getSummary().contains(issueKeyString)){

String commentText = ComponentAccessor.getCommentManager().getComments(eventIssue).last().getBody();

if(commentText.indexOf(issueKeyString) != -1){
stringIndex = commentText.indexOf(issueKeyString);

for(int i = stringIndex + issueKeyString.length(); i < commentText.length(); ++i){

if(Character.isDigit(commentText.charAt(i)) ){
temp += commentText.charAt(i);
}
else
break;
}

}
}
if(temp.length() > 0){
eventIssue.setSummary(temp + " " + eventIssue.getSummary());
}

}

// IssueEventListener implementation -----

public void issueCommented(IssueEvent e){

addIssueKeyToIssueSummary(e);
}

//whether administrators can delete this listener
public boolean isInternal()
{
return true;
}
}

3 answers

0 votes
Deleted user September 24, 2015

Hi Andrew, thanks for the tip, I will give it a shot. Best Regards, Ivan

0 votes
AndrewB September 24, 2015

You might need to call updateIssue to persist the changes you've made to the MutableIssue:

 

Use IssueManager updateIssue call.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

...
		
if(temp.length() &gt; 0){
	eventIssue.setSummary(temp + " " + eventIssue.getSummary());
			
	ComponentAccessor.getIssueManager().updateIssue(user, eventIssue, EventDispatchOption.DO_NOT_DISPATCH, true)
}
0 votes
AndrewB September 24, 2015

Did you create the custom listener in the SciptRunner ScriptListener admin panel? Did it compile without errors? Did you check the log file for errors when running this?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events