Search code examples
javajirajira-rest-java-api

How to set the custom field "startDate" in Jira with a Java API


Here is the code:

public String createDeploymentTask(String project_key, String summary, String description) throws ResponseException { //ADD FIELDS: DATE...
    IssueRestClient issueClient = restClient.getIssueClient();
    IssueInputBuilder iib = new IssueInputBuilder();
    iib.setProjectKey(project_key);
    iib.setSummary(summary);
    iib.setIssueTypeId(new Long(10800));
    iib.setDescription(description);
    iib.setFieldValue("customfield_15031",  new Timestamp(System.currentTimeMillis()));
    IssueInput issue = iib.build();
    BasicIssue issueObj = null;
    try {
        issueObj = issueClient.createIssue(issue).claim();
    } catch (RestClientException e) {
        throw new ResponseException(400, "Input is invalid (e.g. missing required fields, invalid field values, and so forth)\n" + e.getMessage());
    }

    System.out.println("Issue " + issueObj.getKey() + " created successfully");
    return issueObj.getKey();
}

I get the exception:

com.atlassian.jira.rest.client.api.domain.input.CannotTransformValueException: Any of available transformers was able to transform given value. Value is: java.sql.Timestamp: 2018-07-20 17:20:06.65

What format should have the second parameter in

iib.setFieldValue("customfield_15031", new Timestamp(System.currentTimeMillis()));

?


Solution

  • BaseValueTransformer that is used by IssueInputBuilder doesn't accept any time or date related value. You will have to format date on your own and pass as a string value. The format is 2018-07-25 so you will have to use format yyyy-MMM-dd.