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;
}
}
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() > 0){ eventIssue.setSummary(temp + " " + eventIssue.getSummary()); ComponentAccessor.getIssueManager().updateIssue(user, eventIssue, EventDispatchOption.DO_NOT_DISPATCH, true) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.