Create sub tasks issue

Latha August 5, 2015

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 votes
Answer accepted
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.
August 5, 2015

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"

Latha August 5, 2015

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

0 votes
Latha August 5, 2015

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;
}

 

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.
August 5, 2015

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.

Latha August 5, 2015

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

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.
August 5, 2015

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