Create sub tasks issue

Hi,

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();
    issueSubtaskParams.setSummary("Testing...");
    issueSubtaskParams.setProjectId(issue.getProjectObject().getId());
    issueSubtaskParams.setIssueTypeId("5");

    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 vote

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

 

issueSubtaskParams.setAssigneeId(vendor.getName());
Collection<IssueSecurityLevel> islmc =islm.getAllSecurityLevelsForUser(vendor.getDirectoryUser());
for (IssueSecurityLevel issueSecurityLevel : islmc) {
issueSubtaskParams.setSecurityLevelId(issueSecurityLevel.getId());
break;
}

 

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,207 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot