I have a very easy script implemented as a post-function upon issue creation.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Origin")
def cfValue = issue.getCustomFieldValue(cf)
if (cfValue == 'Support') {
issue.setReporter(sthomson)
}
I have also tried issue.setReporter('Steve Thomson'), but that did not work either.
In addition, I did have logging in place and confirmed that "cfValue == 'Support'. Here is the script with the logging:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import org.apache.log4j.Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Origin")
def cfValue = issue.getCustomFieldValue(cf)
myLog.debug("Origins value: " + cfValue)
if (cfValue == 'Support') {
issue.setReporter(sthomson)
}
else {
myLog.debug("Did not update the reporter because value of Origin field was not Support")
}
Please help.
Hello @Edward Greathouse
The thing is that method setReporter accepts ApplicationUser object. You ll need to get it first. Like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Origin")
def user = ComponentAccessor.getUserManager().getUserByName("Steve Thomson")
def cfValue = issue.getCustomFieldValue(cf)
if (cfValue == 'Support') {
issue.setReporter(user)
}
and place your postfunction before change history postfunction.
Thank you Mark, I thought it was something simple like that.
One more thing, it appears I'm not making inside the "if" statement at all. Here are the logged messages:
2018-08-22 06:56:11,513 DEBUG [jira.groovy]: Origins value: Support 2018-08-22 06:56:11,513 DEBUG [jira.groovy]: Did not update the reporter because value of Origin field was not Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to cast value to string directly, like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Origin")
def user = ComponentAccessor.getUserManager().getUserByName("Steve Thomson")
def cfValue = issue.getCustomFieldValue(cf).toString()
if (cfValue == 'Support') {
issue.setReporter(user)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was able to get past the string comparison by casting the custom field value to a string. However, It appears the "user" is returning null.
@Mark Markov, the user "Steve Thomson" is an active directory user who is using Jira with his active directory credentials. Is there a special way for retrieving his user account?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import org.apache.log4j.Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Origin")
def user = ComponentAccessor.getUserManager().getUserByName("Steve Thomson")
def cfValue = issue.getCustomFieldValue(cf).toString()
myLog.debug("Origins value: " + cfValue)
if (cfValue == "Support") {
issue.setReporter(user)
myLog.debug("Updated reporter to: " + user)
}
else {
myLog.debug("Did not update the reporter because value of Origin field was not Support")
}
Here is the log:
2018-08-22 07:07:46,964 DEBUG [jira.groovy]: Origins value: Support 2018-08-22 07:07:46,964 DEBUG [jira.groovy]: Updated reporter to: null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Update*
I changed "Steve Thomson" to "sthomson" and I'm now getting this in the log:
2018-08-22 07:13:13,009 DEBUG [jira.groovy]: Origins value: Support 2018-08-22 07:13:13,025 DEBUG [jira.groovy]: Updated reporter to: sthomson(steve.thomson)
However, the issue still has the reporter as me when I create it. We are getting close. I will post screenshots of where I have the post function and the issue I tested it with.
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.
Okay, lets try to store changes manually via IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import org.apache.log4j.Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Origin")
def user = ComponentAccessor.getUserManager().getUserByName("sthomson")
def cfValue = issue.getCustomFieldValue(cf).toString()
myLog.debug("Origins value: " + cfValue)
if (cfValue == "Support") {
issue.setReporter(user)
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
myLog.debug("Updated reporter to: " + user)
}
else {
myLog.debug("Did not update the reporter because value of Origin field was not Support")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov,
I fixed it by adding the post funciton to the top of the que. Thank you so much for all the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fixed!
Once I moved the post function to the top of the list, I now see "Steve Thomson" as the reporter.
Thank you!
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.