Forums

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

get the issue key of the current issue

Samar Elsayed April 3, 2021

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)

 

2 answers

1 accepted

1 vote
Answer accepted
Samar Elsayed April 4, 2021

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
0 votes
Juan Manuel Ibarra
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 3, 2021

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
}
}
Samar Elsayed April 4, 2021

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.

Suggest an answer

Log in or Sign up to answer