Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Auto create multiple subtasks using Custom field value

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
Tansu Akdeniz Community Leader Jan 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

0 votes

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you