I hope this is an easy one - I am testing out my script ( I know I will have to add an event issue when I finalize my script I am just testing with one issue for now)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.security.roles.ProjectRoleManager
IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("MH-5548")
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.userUtil
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10625")
def system = cField.getValue(issue)
if(system == "Looker (BI)") {
userUtil.getAllUsersInGroupNames(['BI']).each { user ->
watcherManager.startWatching(user, issue)
}
} else {
return "hello"
}
For some reason when I test the value I get null. When I return system I get [Looker (BI)] which I'm assuming it is returning a value within a list.
I'm not sure what I am doing wrong here.
I think it's going wrong in this block:
def system = cField.getValue(issue)
if(system == "Looker (BI)") {
userUtil.getAllUsersInGroupNames(['BI']).each { user ->
watcherManager.startWatching(user, issue)
}
The first line there is fine, but what ends up in "system" is probably not what you think iti is. The type of field determines what object you get back from that line, and because Groovy is weakly typed, it's not complaining when you get something you are not expecting.
For example, ff the field is a multi-select, then you're going to get a list of options back, if it's a single-select, then either an option or a singleton list with one option in it. You'll only get "Looker (BI)" from it as a string if the field is text, and even then, it's not a good idea to compare strings with ==, you should use string1.equals(string2)
So, back to the start. What type of field is the custom field you are reading?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works in my instance with a Select List (Single Choice) field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.groups.GroupManager
IssueManager im = ComponentAccessor.getIssueManager()
GroupManager gm = ComponentAccessor.getGroupManager()
MutableIssue issue = im.getIssueObject("TEST-1234")
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.userUtil
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_13126")
def system = cField.getValue(issue)
log.warn(system)
if(system.toString() == "High") {
gm.getUsersInGroup('jira-administrators').each { user ->
watcherManager.startWatching(user, issue)
}
} else {
return "hello"
}
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.
This should work then. Use log.info(system) to get the value before the block to confirm. In my case, it's [Entity One]
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.groups.GroupManager
IssueManager im = ComponentAccessor.getIssueManager()
GroupManager gm = ComponentAccessor.getGroupManager()
MutableIssue issue = im.getIssueObject("TEST-1234")
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.userUtil
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_55522")
def system = cField.getValue(issue)
log.warn(system)
if(system.toString().equals("[Entity One]")) {
gm.getUsersInGroup('jira-administrators').each { user ->
watcherManager.startWatching(user, issue)
}
} else {
return "hello"
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this and let me know.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.AbstractEvent
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.groups.GroupManager
IssueManager im = ComponentAccessor.getIssueManager()
GroupManager gm = ComponentAccessor.getGroupManager()
MutableIssue issue = im.getIssueObject("MH-5548")
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.userUtil
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10625")
def system = cField.getValue(issue)
if(system.toString() == "[Looker (BI)]") {
gm.getUsersInGroup('BI').each { user ->
watcherManager.startWatching(user, issue)
}
} else {
return "hello"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still doesn't work. I've tried using toString() in different places and it never worked. @Mike Schultz
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.
@Jacob Francois If you add a logging statement within the if block, does it trigger?
if so, you may need to apply the changes to the issue. With something like:
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.event.type.EventDispatchOption
def AuthContext=ComponentAccessor.getJiraAuthenticationContext()
updateIssueRequest = UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH).sendMail(false).build()
issueManager.updateIssue(AuthContext.getLoggedInUser(),
mutableIssue,
updateIssueRequest)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mike Schultz when I run the code I get a null return(or hello). I don't think the issue is with what is inside the if or else statement. the problem is that system == "looker (bi) goes to else when I know it is true.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, as I mentioned, a single-select list won't hold a string, they hold an option.
To compare an option with a string, you probably want the name of the option, not the whole option object.
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.
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.