taskadapter / redmine-java-api

Redmine Java API
Apache License 2.0
270 stars 163 forks source link

Updating custom field of given issue ? #232

Closed hamzaouekdi closed 8 years ago

hamzaouekdi commented 8 years ago

I am trying to update custom fields of an issue which I am getting by it's id ?

RedmineManager mgr = RedmineManagerFactory.createWithApiKey(uri,apiAccessKey); Issue modi=mgr.getIssueManager().getIssueById(65, Include.journals,Include.watchers,Include.attachments,Include.changesets,Include.relations);

CustomField customField=CustomFieldFactory.create(1, "Company Name", "new name") ; modi.addCustomField(customField); mgr.getIssueManager().update(modi);

hamzaouekdi commented 8 years ago

No one can help ????

adrianobr commented 8 years ago

any news?

hamzaouekdi commented 8 years ago

I finally used Restful service by updating the issue with 'PUT' method this way:

URL url1;
try {
url1 = new URL(
 "http://127.0.0.1/redmine/issues/" + issueId+ ".json?key="+ apiAccessKey);
HttpURLConnection httpCon = (HttpURLConnection) url1
                        .openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
httpCon.setRequestProperty(
"Accept-Language",  "fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2");
httpCon.setRequestProperty("User-Agent","Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36");
httpCon.setRequestProperty( "Content-Type","application/xml");
StringBuilder xmlContent = new StringBuilder();
    xmlContent.append("<issue><id>").append(ticketId).append("</id><custom_fields type='array'><custom_field id='5'><value>newValue</value></custom_field>");

xmlContent.append("</issue>");

OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
                                        out.write(xmlContent.toString());
                                        out.close();
                                        httpCon.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
    e.printStackTrace();
}
alexeyOnGitHub commented 8 years ago

documented how to update custom field values in README.md.