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: 

Creating sub task

AKASHB
Contributor
August 21, 2013

I want to write a post function groovy script, in which i need to create 6 sub task, so any help out there from you all genious?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
RambanamP
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 Champions.
August 21, 2013

try with this code(i have used in java), do changes as per your requirement

Issue issue = (Issue) transientVars.get("issue");
	for(int i=1;i<=5;i++){
	createSubtask(issue);
	}
	
	public void createSubtask(Issue sIssue) {
		MutableIssue mutableIssue =ComponentAccessor.getIssueFactory().getIssue();
		mutableIssue.setDescription("Test");		
		IssueType issueType = IssueCustomFieldConstants.constantsManager.getIssueTypeObject(3);//enter subtask issue type id as int
		mutableIssue.setIssueTypeObject(issueType);
		mutableIssue.setPriorityId(3);
		mutableIssue.setSummary("summary");
		mutableIssue.setProjectObject(sIssue.getProjectObject());
		mutableIssue.setReporter(sIssue.getReporter());		
		mutableIssue.setAssignee(sIssue.getReporter());
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("issue", mutableIssue);
		final JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
		User currentUser = authenticationContext.getLoggedInUser();
		try {			
			IssueManager issueManager = ComponentAccessor.getIssueManager();
			Issue issue = issueManager.createIssueObject(currentUser, params);
			SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
			boolean isSubtaskEnabled = subTaskManager.isSubTasksEnabled();
			subTaskManager.enableSubTasks();
			subTaskManager.createSubTaskIssueLink(sourceIssue, issue, currentUser);
			if (!isSubtaskEnabled) {
				subTaskManager.disableSubTasks();
			}

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

TAGS
AUG Leaders

Atlassian Community Events