I have a requirement to provide parent ID when the jira issue is created programatically.
When I set the parent ID, my issue (sub task/sub bug) has to be created under the given parent ID issue.
Any idea, how can I do this.
I jsut set the issue id long value to my newly creatin issue. But nothing happens.
issue.parentID(my_parent_Id's_ID);
Sahan,
This code worked for me:
private void convertToSubtask(MutableIssue issue, Issue parentIssue)
{
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager()
issue.setProjectObject(parentIssue.getProjectObject())
issue.setIssueTypeObject( subTaskManager.getSubTaskIssueType( this.defaultSubtaskId ) )
issue.setParentId(parentIssue.getId())
issue.store()
subTaskManager.createSubTaskIssueLink(parentIssue, issue, this.runAs)
//reindex
this.reindexIssue(issue)
}
Keep in mind what Nick said about the timing...
Great Thanks Gaston. I will try that and let you know how it goes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gaston,
Thanks for the quick reply. I tried subTaskManager.createSubTaskIssueLink(Issue parent, Issue subTask, User user) API. It says NoSuchMethod.
And, For Nic, I jsut tried. It creates the sub task issue seperately. But it doesn't create the subtask under the parent issue.
I do reindex after issue creation too.
Am I doing something wrong..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gaston.
I managed to do your way with reflections. That worked!
Thank you both!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure where you got "parentID" from, but it's not going to work because you might not have it until later if you are running this on "create"
Try using the issue object for the parent:
newSubTask.setParentObject(issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sahan,
you need to use the subtaskmanager https://docs.atlassian.com/jira/server/com/atlassian/jira/config/SubTaskManager.html
there are a lot of post in the community with code sample, for example:
If you need more help I think I have a working snippet somewhere
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Gaston,
Please share... My code not working. Tried a lot..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.