Auto create multiple subtasks using Custom field value

shital chande January 30, 2020

Hi,

 

I want to create automatically creating subtasks for taken the custom field value(int) using script runner.

What do i need to do?

Anyone suggest to me.

2 answers

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2020

There are a few scripts in the library you might want to have a look at (as in "copy them") - see https://library.adaptavist.com/search?page=1&products=jira&term=create

0 votes
Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 30, 2020

Hi @shital chande ,

You should be familiar to scripting. There are lots of examples in Vendor website and community, please check this link. After finalizing your code, go to

  • Workflow -> Related transition -> Post-function -> Script Runner post-function -> custom script than paste it.
    *Btw, it is better to add as a ".groovy" file to JIRA_HOME/scripts directory and choose this file within Jira. 

Following code may guide you create sub-task. You can convert according your needs.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.IssueInputParameters

try {

Issue issue = ComponentAccessor.getIssueManager().getIssueObject(issue.key);
IssueService issueService = ComponentAccessor.getIssueService();
ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(10000L);
issueInputParameters.setIssueTypeId("10000");
issueInputParameters.setSummary(issue.getSummary());
issueInputParameters.setDescription(issue.getDescription());

IssueService.CreateValidationResult createValidationResult = issueService.validateSubTaskCreate(loggedInUser, issue.getId(), issueInputParameters);
log.error(createValidationResult.errorCollection)

if (createValidationResult.isValid()) {
IssueService.IssueResult createResult = issueService.create(loggedInUser, createValidationResult);
if (createResult.isValid()) {
log.debug("Subtask successfully created : " +createResult.getIssue().getKey());
subtaskManager.createSubTaskIssueLink(issue, createResult.getIssue(), adminUser)
} else {
log.error("createResult is not valid.");
}
} else {
log.error("createValidationResult is not valid.");
}

} catch (Exception e) {
log.debug(e);
}

Regards

Suggest an answer

Log in or Sign up to answer