Hi Community Members,
I have Components with owners as developers so that the workflow auto assigns the tickets to component owners when ever an issue is created.
Now my requirements is while transition from Development to QA state in the workflow i wanted to add an post function to auto assign tickets to different QA - users based on component names, i have tried using script runner Add-on and added an post function - custom script
Syntax:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import org.apache.log4j.Logger
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
MutableIssue issue = issue
Project project = issue.getProjectObject()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customFieldId=11302")
def cFieldValue = issue.getCustomFieldValue(cField)
def components = issue.getComponents()
if (cFieldValue == 'Fixed') {
if (components == 'demo x') {
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName('Test_User1'))
}
else if (components == 'demo y') {
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName('Test_User2'))
}
else if (components == 'demo two') {
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName('Test_User3'))
}
}
But now i get Null Pointer Exception Error: any suggestions please ??
2018-12-07 00:26:30,186 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-12-07 00:26:30,188 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: DEMO-106, actionId: 61, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$3.call(Unknown Source) at Script814.run(Script814.groovy:26)
Hi @Tom Lister thanks for the help - the custom script now runs successfully but, as shown in the code - logic i'am unable to auto assign issue to users based on component names - any suggestions ??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would start by adding logging statements to each block setting values to check if they are being executed
log.debug(cFieldValue)
log.debug(components)
also check atlassian-Jira.log for any messages related to 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 @Tom Lister thanks for the immediate response, as suggested i have added the log.debug to check both the values
log.debug(cFieldValue)
log.debug(components)
Was able to retrieve cFieldValue = Fixed as required but the component value retrieved is different
Here is the log out-put - can you please suggest changes to my code to get just the "component name" assigned to components
2018-12-07 20:00:41,272 DEBUG [groovy.Condition]: Fixed 2018-12-07 20:00:41,273 DEBUG [groovy.Condition]: [ProjectComponentImpl { name='demo x', description='test ', lead='saiprakash_avula', assigneeType='1', projectId='10101', id='11907' }]
Thanks,
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai
the components value is a collection of Project Components as many components could be associated with an issue
In code terms you will need to iterate through the list and make checks on component.name
Where you call get components try getComponents.toList()
I’m afraid it’s quite late here and I will be offline for a while
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tom Lister thanks for helping out will try implementing as suggest and get back if issue.
Thanks,
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
try this syntax
If (issue.components*.name.contains('YOURTEXT'))
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.
The final solution which worked for me - this may help someone
I had the Created Validator added - "Universal Validator" which check for my custom field Dev.Resolution value if "Fixed" the transition to QA
To auto assign issue to QA - members based on component names - i had added the post function script using script runner - "Custom Script"
Syntax:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import org.apache.log4j.Logger
import org.apache.log4j.Category
String userName;
def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)
MutableIssue issue = issue
Project project = issue.getProjectObject()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11302")
def cFieldValue = issue.getCustomFieldValue(cField)
log.debug(cFieldValue)
if (issue.components*.name.contains('demo x')) {
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName('Test_User1'))
}
else if (issue.components*.name.contains('demo y')) {
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName('Test_User2'))
}
else if (issue.components*.name.contains('demo two')) {
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName('Test_User3'))
}
Regards,
Sai
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.