Question


I am using the JRJC jira-rest-java-client-2.0.0-m2.
My goal is to be able to copy a custom field from an issue and create a new issue with the value. This usually works perfectly fine:

Field trigger = issue.getFieldByName("Trigger");
if (trigger != null) {
    newIssue.setFieldValue(trigger.getId(), trigger.getValue());
}

(The newIssue is an object of type IssueInputBuilder; the issue of type Issue)

But it does not work with a dropdown(single-selection), this throws the following exception:

com.atlassian.jira.rest.client.domain.input.CannotTransformValueException: Any of available transformers was able to transform given value. Value is: org.codehaus.jettison.json.JSONObject: {"self":"http:\/\/localhost:8080\/rest\/api\/2\/customFieldOption\/10100","value":"SQL Statement","id":"10100"}
    at com.atlassian.jira.rest.client.domain.input.ValueTransformerManager.apply(ValueTransformerManager.java:83)
    at com.atlassian.jira.rest.client.domain.input.IssueInputBuilder.setFieldValue(IssueInputBuilder.java:135)
    at com.sonydadc.lfiala.jira.CopyUtil.copy(CopyUtil.java:152)
    at com.sonydadc.lfiala.jira.JiraUtil.copyTask(JiraUtil.java:90)
    at com.sonydadc.lfiala.jira.Start.main(Start.java:13)

Setting the value directly does not work eiter:

Field trigger = issue.getFieldByName("Trigger");
        if (trigger != null) {
            newIssue.setFieldValue(trigger.getId(), trigger);
        }

When i try this, this exception is thrown:

com.atlassian.jira.rest.client.RestClientException: Could not find valid 'id' or 'value' in the Parent Option object.
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:165)
    at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:159)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:48)
    at com.atlassian.httpclient.api.ResponsePromiseMapFunction.apply(ResponsePromiseMapFunction.java:12)
    at com.atlassian.util.concurrent.Promises$Of$3.apply(Promises.java:285)
    at com.atlassian.util.concurrent.Promises$2.onSuccess(Promises.java:162)
    at com.google.common.util.concurrent.Futures$7.run(Futures.java:1072)
...

These exceptions get thrown when the jira-client tries to set the value to the issueinputbuilder.
How do i solve this?

Thanks in advance, Laurenz

EDIT i tried the same with the newest m25 versions of jira-rest-java-client-api and jira-rest-java-client-core, and it didn't work either

FYI i have already googled. a lot. i didnt find anything that could solve my issue(at least not on the first few pages :/)

Was it helpful?

Solution

Okay i have solved it myself :)

If anyone wonders here's how:

IssueField trigger = issue.getFieldByName("Trigger");
        if (trigger != null) {
            JSONObject triggerJO = (JSONObject) trigger.getValue();
            newIssue.setFieldValue(trigger.getId(), ComplexIssueInputFieldValue.with("value", triggerJO.get("value")));
        }

This runs with the new api versions m25(jira-rest-java-client-api and jira-rest-java-client-core).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top