Creating sub task

AKASHB 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

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 Leaders.
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();
		}
	}

Suggest an answer

Log in or Sign up to answer