Hello Community,
I do have an issue with a groovy script in Jira, where I successfully create a arbitrary number of linked issues based on a customField that holds user objects. I loop over these objects with a for loop and the issues get created fine, but I would like to set the approvers field used for Jira Service Desk to be set to the current loop item. I have this code for that part:
for (it in users) {
log.debug "Users loop STARTED"
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setSummary("DETAIL - $issue.summary")
newIssue.setProjectId(issue.projectId)
newIssue.setDescription(issue.description)
newIssue.setAssigneeId("$it")
newIssue.issueTypeId = "10200"
log.debug "Assignee: "+ it
String Approver = it.toString()
ApplicationUser appUser = userManager.getUserByKey(Approver)
if(appUser == null) {
appUser = userManager.getUserByName(Approver);
log.debug("did not find an application user with key '" + Approver + "'. found application user by using as name: " + String.valueOf(appUser))
}
log.debug "Approver: " + Approver
newIssue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10100),Approver)
Map<String, Object> newIssueParams = ["issue": newIssue] as Map<String, Object>
//issueManager.createIssueObject(currentUser, newIssueParams)
issueManager.createIssueObject(currentUser, newIssueParams)
IssueLinkManager linkManager = ComponentAccessor.getIssueLinkManager()
log.debug("Issue Link Types : " + IssueLinkType)
linkManager.createIssueLink(issue.getId(), newIssue.getId(), 10003, 1, currentUser);
log.debug "Users loop END"
}
I get the log message as follows:
2018-10-24 18:01:34,786 http-nio-2990-exec-8 DEBUG admin 1081x403153x1 14d93yw 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.h.a.jira.workflow.SplitIssue] Users loop STARTED
2018-10-24 18:01:34,789 http-nio-2990-exec-8 DEBUG admin 1081x403153x1 14d93yw 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.h.a.jira.workflow.SplitIssue] Assignee: admin(admin)
2018-10-24 18:01:34,805 http-nio-2990-exec-8 DEBUG admin 1081x403153x1 14d93yw 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.h.a.jira.workflow.SplitIssue] did not find an application user with key 'adm
in(admin)'. found application user by using as name: null
2018-10-24 18:01:34,808 http-nio-2990-exec-8 DEBUG admin 1081x403153x1 14d93yw 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.h.a.jira.workflow.SplitIssue] Approver: admin(admin)
2018-10-24 18:01:34,851 http-nio-2990-exec-8 ERROR admin 1081x403153x1 14d93yw 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] **********************************
***************************************************
2018-10-24 18:01:34,854 http-nio-2990-exec-8 ERROR admin 1081x403153x1 14d93yw 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: W
GPS-78, actionId: 1, file: <inline script>
com.atlassian.jira.exception.CreateException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and
see: http://confluence.atlassian.com/x/3McB
Do you have any idea what I may need to change to make it happen?
Thank you and best regards,
Nico
Hi Nico,
'users' is a list of user objects, yes? You won't need to use the userManager because 'it' is already going to be a user object. Also, I think you have to set the Approvers field with a list of users. See if this script works
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkType
for (it in users) {
log.debug "Users loop STARTED"
def newIssue = issueFactory.cloneIssue(issue)
newIssue.setSummary("DETAIL - $issue.summary")
newIssue.setProjectId(issue.projectId)
newIssue.setDescription(issue.description)
newIssue.setAssigneeId("$it")
newIssue.issueTypeId = "10200"
log.debug("Assignee: " + it.name)
log.debug("Approver: " + it.name)
newIssue.setCustomFieldValue(customFieldManager.getCustomFieldObject(10100), [it])
Map<String, Object> newIssueParams = ["issue": newIssue] as Map<String, Object>
//issueManager.createIssueObject(currentUser, newIssueParams)
issueManager.createIssueObject(currentUser, newIssueParams)
IssueLinkManager linkManager = ComponentAccessor.getIssueLinkManager()
log.debug("Issue Link Types : " + IssueLinkType)
linkManager.createIssueLink(issue.getId(), newIssue.getId(), 10003, 1, currentUser);
log.debug "Users loop END"
}
Regards,
Josh
Hey Josh,
you did it! :-) I tried your line and it works like charm!
Thank you very much and a nice weekend for you!
Best regards,
Nico
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nico,
Glad to hear you got it working! :)
Thx for using ScriptRunner.
Regards,
Josh
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.