I am trying to create a Custom Listener that fires on the SprintStartedEvent.
What I want for the outcome is when a Sprint is started the value that is in the custom field "Planned Assignee" which is a single user picker field will be copied into the Assignee field.
I am not sure how to get this started. I haven't been able to find any previous questions asked that are helpful in this situation.
I do not know your problem but are you using that in postfunction.
Below code works and assigns issuekey variable in postfunction script.
import com.atlassian.jira.issue.Issue Issue issue = issue
def issuekey = issue.getKey()
Or simply type all code of yours so that we can better analyze.
import groovy.json.*
import groovyx.net.http.*
import static groovy.json.JsonOutput.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.spi.Step
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.mail.Email
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
def userManager = ComponentAccessor.getUserManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def impact = (String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Impact"))
def watcherManager = ComponentAccessor.getWatcherManager()
def watchersList = watcherManager.getCurrentWatcherUsernames(issue)
def watchersMailList = []
def assignee = userManager.getUserByName(issue.reporter.name)
def assigneeMail = assignee.getEmailAddress()
for (name in watcherManager.getCurrentWatcherUsernames(issue))
{
def user = userManager.getUserByName(name)
watchersMailList.add(user.getEmailAddress().toString())
}
public class RFC_Notification {
Issue issue = issue
def issueKey = issue.getKey()
IssueManager issueManager = ComponentManager.getInstance().getIssueManager()
def access_token = "*my_token*"
String targetUrl = '*my_api_link*'
def http = new HTTPBuilder(targetUrl)
def result = http.request(POST) {
http.ignoreSSLIssues()
uri.path = '/v1/rooms'
requestContentType = URLENC
body = [title:issueKey]
headers.'Authorization' = "Bearer " + access_token.toString()
headers.'Accept'='application/json'
response.success = { resp, JSON ->
return JSON
}
}
def memberAdding(String userMail,Boolean moderator) {
def http = new HTTPBuilder(targetUrl)
http.ignoreSSLIssues()
http.request(POST) {
uri.path = "/v1/memberships"
requestContentType = URLENC
body = [roomId:result['id'],personEmail:userMail,isModerator:moderator]
headers.'Authorization' = "Bearer " + access_token.toString()
headers.'Accept'='application/json'
response.success = { resp,json ->
println prettyPrint(toJson(json))
}
}
}
}
def test = new RFC_Notification()
for (i in watchersMailList)
{
if (assigneeMail.toString() == i)
{
test.memberAdding(i,true)
}
else {
test.memberAdding(i,false)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, thanks
You can not use below statement in your custom class.
Issue issue = issue
You should use this part above (in the main groovy part) and pass it to your class.
e.g.
def test = new RFC_Notification(issue)
public class RFC_Notification {
Issue issue;
RFC_Notification(Issue issue) {
this.issue = issue
}
}
I hope I was clear
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any update Andrew? Did it help? Do you need more help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
All is working. Thank you everyone)
Simply added a constructor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great to hear that, please do not forget to accept the answer for the other community members to help them find the correct answer easily.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to assign issue.getKey() to a variable and use that variable in anonymous method.
def issueKey = issue.getKey()
def http = new HTTPBuilder(targetUrl)
def result = http.request(POST) {
http.ignoreSSLIssues()
uri.path = '/v1/rooms'
requestContentType = URLENC
body = [title:issueKey]
headers.'Authorization' = "Bearer " + access_token.toString()
headers.'Accept'='application/json'
response.success = { resp, JSON ->
return JSON
}
}
Hope that helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still
java.lang.NullPointerException: Cannot invoke method getKey() on null object
But when I debug my code using log.debug or log.error etc It return me correct issue name and ID . And I even review the type of this variable using getClass() and I see String type (all is okay). But when I put this variable to body , still see NullPointerException. I put for example userMail (using getEmailAddress) and all is working correctly. But getKey is not working. And I don't know why
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this method "${issueKey}" and now I see
groovy.lang.MissingPropertyException: No such property: issue for class
But I declared variable (Issue issue = issue), still the problem (without this variable or with this variable)
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.