Setting issue type for a subtask

Priya Thevar October 8, 2013

I have to create a subtask with Issue type as Interview. Need help.

This is my code

def prjisstyp = issueTypeManager.getIssueTypesForProject(issue.getProjectObject()) as Collection<IssueType>

def myissue = prjisstyp.find{it.name == 'Interview'}

if (myissue && myissue.isSubTask())

{

newSubtask.setIssueTypeObject(myissue);

log.warn("Issue Type: ${newSubtask.issueTypeObject.name}");

}

Log shows error as

The script failed : javax.script.ScriptException: javax.script.ScriptException: com.atlassian.jira.exception.CreateException

how to print the list of all subtask issue type?

1 answer

1 accepted

0 votes
Answer accepted
Bharadwaj Jannu
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.
October 8, 2013

I don't know about groovy syntax, but the following java code might help you.

User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

Issue parentIssue={getting the parent issue object};

MutableIssue subtaskIssue=ComponentAccessor.getIssueFactory().getIssue();

subtaskIssue.setProjectId(parentIssue.getProjectObject().getId());

subtaskIssue.setParentId(parentIssue.getId());

subtaskIssue.setIssueTypeId("{id for your interview}");

subtaskIssue.setPriorityId(parentIssue.getPriorityObject().getId());// I'm assigning priority of parent issue here.

subtaskIssue.setReporter(user);

subtaskIssue.setSummary("Subtask-issue"+parentIssue.getSummary());

try{
 Issue subTask = ComponentAccessor.getIssueManager.createIssueObject(user, subtaskIssue);
ComponentAccessor.getSubtaskManager.createSubtaskIssueLink(parentIssue,subTask,user);

ImportUtils.setIndexIssues(true);
ComponentAccessor.getIssueIndexManager().reIndex(subTask);

}
catch(Exception e)
{
e.printStackTrace();
}

Priya Thevar October 8, 2013

How do I print all the issue types available?

Bharadwaj Jannu
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.
October 8, 2013

ComponentAccessor.getConstantsManager().getAllIssueTypeObjects();

or

ComponentAccessor.getConstantsManager().getAllIssueTypeIds() ;

Priya Thevar November 11, 2013

Thank you!! It helped.

Bharadwaj Jannu
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.
November 12, 2013

glad to hear it helped.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events