Hi
I have created a custom listener script below ( and this is my first time doing that ) that assigns the issue ( created / edited ) to certain user based on certain custom field value but I got an issue :
1- I need the script to run on the current issue instead of putting its key manually in getIssueByCurrentKey I have tried to use issue.getKey() but faced the error below :
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.issue.MutableIssue.getKey() is applicable for argument types: () values: [] Possible solutions: getAt(java.lang.String), notify(), every(), grep(), grep(java.lang.Object), every(groovy.lang.Closure) at Script736.run(Script736.groovy:32)
UPDATE
I have solved the problem as I said in my reply to the first comment.
here is the new working code :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.event.issue.IssueEvent
def logg = Logger.getLogger("com.acme.CreateSubtask")
logg.setLevel(Level.DEBUG)
String user;
def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObject("customfield_32946");
def cfVal = issue.getCustomFieldValue(cf)
def userr = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
switch(cfVal as String){
case { it == "[Assistant, Ask to Google]" || it == "[Assistant, Request to Google]" || it == "[Assistant, VF Office Hours]" }:
user = "hossam@it.com";
break;
}
logg.debug issue
def issueService = ComponentAccessor.issueService
def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setAssigneeId(user)
def updateValidationResult = issueService.validateUpdate(userr, issue.id, issueInputParameters)
issueService.update(userr, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, false)
I have solved this problem. It was a misunderstanding from my side, I just needed to use issue to get the issue key as shown in the updated code :
logg.debug issue
Hi! you need to do something similar to this
import org.apache.log4j.Category
import org.apache.log4j.Logger
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.security.JiraAuthenticationContext;
class ExampleListener extends AbstractIssueEventListener{
@Override
void workflowEvent(IssueEvent event){
def log = Logger.getLogger("ExampleListener.groovy")
//Issue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("BO-2940"); //Line for testing
Issue issue = event.issue;
IssueService issueService = ComponentAccessor.getIssueService();
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser user = authContext.getLoggedInUser();
//Rest of your code
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Juan Manuel Ibarra
Thank you! I have solved this part. It was a misunderstanding from my side, I just needed to use issue to get the issue key.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.