HI All,
I'm using groovy script to make a particular user as a assignee on selection of an option in single select custom field. This custom field is having multiple contexts .
My script is taking only few options from the custom field list and ignoring the others. I think, i'm missing out a logic on adding the exact context which my project is using.
Please help me in this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
def systemUserMap = [
Option1: "abc",
Option2: "cde",
["Option3" ,"Option4","Option5" ] : "efg"
]
if(webwork.action.ActionContext.getRequest().getParameter("assignee") == '-1'){
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Track")
def cfTrack = issue.getCustomFieldValue(cf)
if(cfTrack ) {
userName = systemUserMap[cfTrack.value]
log.error(userName)
log.error(cfTrack);
def assignee = ComponentAccessor.userManager.getUserByName(userName)
issue.setAssignee(assignee)
}
}
you could try with this code:
import com.atlassian.jira.component.ComponentAccessor
def systemUserMap = ["Option1": "abc", "Option2": "cde", "Option3": "efg", "Option4": "efg", "Option5": "efg"]
if (issue.assignee == null) {
def customFieldManager = ComponentAccessor.customFieldManager
def cf = customFieldManager.getCustomFieldObjectByName("Track")
def cfTrack = issue.getCustomFieldValue(cf).toString()
if (cfTrack) {
def userName = systemUserMap[cfTrack]
def assignee = ComponentAccessor.userManager.getUserByName(userName)
def issueService = ComponentAccessor.issueService
def validateAssignResult = issueService.validateAssign(assignee, issue.id, assignee.name)
issueService.assign(assignee, validateAssignResult)
}
}
Thank you for your response. I have tried the code as you suggested but getting the error as below.
error
["Atlassian jira "= "user5"] is a constant expression, but it should be a variable expression at line: 8 column: 26.
Unexpected node type: EXPR found when expecting type: LABELED_ARG at line: 9 column: 5. File: Script409.groovy
Code
import com.atlassian.jira.component.ComponentAccessor
def systemUserMap =
[
Option1 = "user1",
option2 = "user2",
option3 = "user3",
option4 = "user4",
"Atlassian jira "= "user5",
"Dev Analytics" = "user6",
"Cloud DevSecOps "= "user6" ,
"Live Egnineering" = "user6" ,
SRE= "user6",
CodeStore = "user7",
Service Store ="user7",
Market Places="user7"
]
if(issue.assignee == null) {
def customFieldManager = ComponentAccessor.customFieldManager
def cf = customFieldManager.getCustomFieldObjectByName("Track")
def cfTrack = issue.getCustomFieldValue(cf).toString()
if (cfTrack) {
def userName = systemUserMap[cfTrack]
def assignee = ComponentAccessor.userManager.getUserByName(userName)
def issueService = ComponentAccessor.issueService
def validateAssignResult = issueService.validateAssign(assignee, issue.id, assignee.name)
issueService.assign(assignee, validateAssignResult)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
when you define the systemUserMap, the keys must be all strings; so you should add double quote where missing.
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.
yes, but you still have to replace the equals with the colons.
The correct definition of your map is the following:
def systemUserMap =
[
"Option1" : "user1",
"option2" : "user2",
"option3" : "user3",
"option4" : "user4",
"Atlassian jira" : "user5",
"Dev Analytics" : "user6",
"Cloud DevSecOps" : "user6" ,
"Live Egnineering" : "user6" ,
"SRE" : "user6",
"CodeStore" : "user7",
"Service Store" : "user7",
"Market Places" : "user7"
]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2022-06-30 12:24:57,678 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed for user 'vijayaramya.allena'. View here: <jira domine>/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Software+Simplified+Workflow+for+Project+QAUT&descriptorTab=postfunctions&workflowTransition=1&highlight=1
java.lang.IllegalArgumentException: Issue cannot be null.
at com.atlassian.jira.issue.fields.layout.field.AbstractFieldLayoutManager.getFieldLayout(AbstractFieldLayoutManager.java:137)
at com.atlassian.jira.bc.issue.DefaultIssueService.assign(DefaultIssueService.java:582)
at com.atlassian.jira.bc.issue.IssueService$assign$1.call(Unknown Source)
at Script544.run(Script544.groovy:28)
Thanks @Andrea Pannitti ,
I have tried creating the issue, but not able to auto-assign it to the users, Above is the error log.
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.
I placed this in the postfuntion : Custom Script post-function(scriptrunner ) on " create " transition of the workflow
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think that the problem is in the postfunction position. You must move it after the "Creates the issue originally".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks a lot, it worked like charm,, I'm so glad . thank you so much for your time.
Allena
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.