Forums

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

Error while creating sub-task using scriptrunner

Jaspreet Kaur
Contributor
August 15, 2020

Hello Team,

I am using below code to create sub-task but i am getting error as in attached screenshot.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.security.JiraAuthenticationContext

def constantManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()

//Issue parentIssue = issue
def parentIssue = issueManager.getIssueObject("PUN-470")

if (parentIssue.getIssueTypeObject().getName() == 'Sub-task')
return

//create new issue as sub task
def newSubtask = issueFactory.getIssue()
newSubtask.summary = "new subtask"
newSubtask.description = "subtask explanation"
newSubtask.setProjectId(parentIssue.getProjectId())
newSubtask.setIssueTypeId("143454") //issue type id must be subtask type's id
newSubtask.setParentId(parentIssue.getId())
newSubtask.setAssigneeId("user1")
newSubtask.setReporterId("user2")
newSubtask = issueManager.createIssueObject(user, newSubtask)

//link subtask to parent task
def subTaskManagerLink = ComponentAccessor.getSubTaskManager()
subTaskManagerLink.createSubTaskIssueLink(parentIssue, newSubtask, user)

parentIssue.store()

 

error-subtask.PNG

1 answer

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2020

The error message has nothing to do with your script as far as I can see.

Can you tell us where you are using the script? 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events