Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create multiple linked issues in postfunction with scriptrunner

Maro Hamamjyan 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

0 votes
Kat Warner
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 27, 2020

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events