Reputation: 4999
Is there a way to create a subtask using JRJC v1.0? I've been unable to find any good documentation on this. Any sample codes out there?
It seems like it's not supported via the library but possible using straight REST API.
JIRA v5.1.5
Upvotes: 3
Views: 6780
Reputation: 126
I was able to put together the below code that worked.
IssueInputBuilder issueBuilder = new IssueInputBuilder("Project1", 5L);//5 is the id for subtask type. You can know the id of subtask type by querying this REST api /rest/api/2/issue/createmeta
issueBuilder.setDescription(">> Test Description");
issueBuilder.setSummary("Test summary");
issueBuilder.setProjectKey("Project1");
Map<String, Object> parent = new HashMap<String, Object>();
parent.put("key", "SOMEISSUE-234");
FieldInput parentField = new FieldInput("parent", new ComplexIssueInputFieldValue(parent));
Map<String, Object> customField = new HashMap<String, Object>();
customField.put("value", "someValue");//This is some custom field value on the subtask
customField.put("id", "12345");//This is the id of the custom field. You can know this by calling REST GET for a manually created sub-task
issueBuilder.setFieldInput(parentField);
issueBuilder.setFieldValue("customfield_12345", new ComplexIssueInputFieldValue(customField));//here again you have to query an existing subtask to know the "customfield_*" value
com.atlassian.jira.rest.client.domain.input.IssueInput issueInput = issueBuilder.build();
BasicIssue bIssue = restClient.getIssueClient().createIssue(issueInput, pm);
System.out.println(">>> " + bIssue.getKey());
Upvotes: 6
Reputation: 6891
The REST API http://docs.atlassian.com/jira/REST/latest/#id326540 has a comment:
Creating a sub-task is similar to creating a regular issue, with two important differences:
the issueType field must correspond to a sub-task issue type (you can use /issue/createmeta to discover sub-task issue types), and you must provide a parent field in the issue create request containing the id or key of the parent issue.
So I think that the regular createIssue method should work, but you need to make sure you have passed in an extra FieldInput object constructed with ("parent", "ABC-123")
I'd be surprised if linking using the subtask link type actually works.
Upvotes: 2
Reputation: 17846
You create an issue as you normally would (example), but set the issue type to the required subtask type. Then, to link the subtask to it's parent use linkIssue
, something like:
LinkIssuesInput linkIssuesInput = new LinkIssuesInput("TST-1", "TST-2", "jira_subtask_link", Comment.valueOf("simple comment"));
issueClient.linkIssue( linkIssuesInput , pm);
I haven't tested it myself, I've used the XML-RPC in old JIra, and python-jira in new ones. The full API is available here
Upvotes: 4