The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create multiple linked issues in postfunction with scriptrunner

Maro Hamamjyan
Contributor
September 25, 2020

Hello,

Based on count of values chosen in a field ("Test1" in my example) in customer portal, I need linked issues to be created, so that in case 3 values are chosen in customer portal, 3 linked issues should be created.

I solved the problem by using subtasks, but as subtasks in Service Desk do not support approval process, I need to use linked issues in stead of subtasks. Can you please help with some code? Here is my code, using subtasks:

IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("SDAT-1156")
def customFieldManager = ComponentAccessor.customFieldManagerdef cField = customFieldManager.getCustomFieldObjectsByName("Test1")[0]
def cFieldValue = cField ? issue.getCustomFieldValue(cField) : "Field doesn't exist"
////     For Sub tasks  ////////
def constantManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
    
Issue parentIssue = issuedef reporter = parentIssue.reporter.namelog.warn("The reporter is " + reporter)
log.warn "====================Start of Log=============================="
log.warn "Custom field value type or class" + cFieldValue.getClass()def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Group owner")
log.warn cascadingSelect
cFieldValue.each{i->
   
    MutableIssue newSubTask = issueFactory.getIssue()
 newSubTask.setAssigneeId(parentIssue.assigneeId)
 newSubTask.setSummary("$i")
 newSubTask.setReporter(parentIssue.reporter)
 newSubTask.setParentObject(parentIssue)
 newSubTask.setProjectObject(parentIssue.getProjectObject())
 newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
 it.getName() == "Group-SubTask"
 }.id)
  
def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
 
 // for JIRA v7.* and V8.*                                        
 issueManager.createIssueObject(user, newIssueParams)
 subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) log.warn "Issue with summary ${newSubTask.summary} created"
        
    log.warn "Group is: $i "
}
   
log.warn "Selected groups are: " +cFieldValue
log.warn "Reporter is: " + reporter
log.warn "====================End of Log=============================="

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Kat Warner
Atlassian Partner
September 27, 2020

Hi @Maro Hamamjyan you may want to contact Adaptavist directly though their support portal.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events