Create sub tasks issue


I'm trying to create few subtasks based on custom field values. For example if i select 2 users in  user pick(multiple), two sub tasks to be created and assigned to that users selected along with main tasks(this is not yet implemented  as of now). Im just creating a sub task with static values. Here is the steps followed

  1. Created custom plugin
    public class MyCreatePostFunction extends AbstractJiraFunctionProvider {

    public void execute(Map transientVars, Map args, PropertySet ps)
    throws WorkflowException {
    MutableIssue issue = getIssue(transientVars);

    IssueInputParameters issueSubtaskParams = issueService.newIssueInputParameters();

    CreateValidationResult validationResult = issueService.validateSubTaskCreate(user,issue.getId(), issueSubtaskParams);
    IssueService.IssueResult issueResult = issueService.create(user, validationResult);



2. Added this post function after "Creates the issue originally."  here is the order 

  • Creates the issue originally.
  • Successfully created subtasks (MyCreatePostFunction )
  • Re-index an issue to keep indexes in sync with the database.
  • Fire a Issue Created event that can be processed by the listeners.                                               

When i try creating issue, the above code keeps create the subtasks in infinite loop. Please guide me how to avoid this issue. 





2 answers

1 accepted

0 votes
Accepted answer

Your code is recursing, with the subtask issue creation triggering another call to the code every time.  Try creating a new workflow that does not use your post-function, and associate that with the subtasks, OR, in your code, add something like "if issue.getType() = subtask, then exit without trying to create anything"

Thanks a lot!! it works  after changing workflow for subtasks

Hi Nic Brough

While creating sub tasks, im trying to set assignee and security level for the issue. But those values have been overridden automatically after executing this line

issueService.validateSubTaskCreate(user,issue.getId(), issueSubtaskParams);


any idea?

Here is the code snippet


Collection<IssueSecurityLevel> islmc =islm.getAllSecurityLevelsForUser(vendor.getDirectoryUser());
for (IssueSecurityLevel issueSecurityLevel : islmc) {


Ok, I'm not sure what vendor.getName() would do, but my best guess is that it's not returning a user object that the assignee field would take. For the security level, it won't work. Subtasks have the same security level as their parent.

Hi Nic, Thanks for the answer. I could see the username if inspect vendor.getName() line. Im pretty sure it returns username and setAssignee() accepts string only. #2: How do i restrict the access to subtasks of each individual vendors. for example, Vendors should not be able to see the subtasks each other whereas main task and all subtasks can be accessed by the user who creates them. how do i achieve it? Will be helpful if you provide some inputs on this

Hmm, yes, the api for setAssignee does say "user" or "string" (I've only ever used user, so I didn't know about string). Problem is, I don't know what that string might be. I'd take a guess at login id rather than name. On the security, there's no easy way to do it - the security level comes from the parent. You *might* be able to do it if you added a custom field for "vendor" (a group?), added that to the subtask and used it in the security scheme, but I'm not sure.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,086 views 4 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you