taskadapter / redmine-java-api

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

Add or Increment Custom Fields #235

Closed adrianobr closed 8 years ago

adrianobr commented 8 years ago

how to create and add custom fields to redmine api? example code?

hamzaouekdi commented 8 years ago
Issue issue=IssueFactory
                .createWithSubject(ticketSubject);

CustomField customField=CustomFieldFactory.create(customFieldId);
customField.setValue(value);
issue.addCustomField(customField);
redmineManager.getIssueManager().createIssue(issue);
adrianobr commented 8 years ago

thank you!

I need now retrieve the description of the possible values for a custom field, idea?

hamzaouekdi commented 8 years ago

I am out of office now, tomorrow I will check my source code and see if I already have an example

adrianobr commented 8 years ago

ok, thanks for your help!!

adrianobr commented 8 years ago

news?

hamzaouekdi commented 8 years ago

Sorry I didn't found any example in my source code but here is a little reflection that came to my mind, normally it will work :

Issue issue=redmineManager.getIssueManager().getIssueById(issueId, Include.journals);
CustomField cf=issue.getCustomFieldById(customFieldId);
String description=cf.getName();
String value=cf.getValue();
adrianobr commented 8 years ago

yes, now I can capture the name and value. My problem is when this custom field is an enumerator. Example: My field can take the following values: {[value: 1 text: "One"], [value: 2 text: "Two"], [value: 3 text: "Three"]}

If I capture the custom field id will have: ID: X Description: My Field Value: 2 (for example) Values: null ???

I am integrating with another system where the only key I get is the description "One", "Two", "Three" and register a task I set the custom field by Value (1, 2, 3). Ie must have the list of Values (with description) to know what value to assign to the custom field.

Can you help me?

hamzaouekdi commented 8 years ago

Have you tried List<String> values=cf.getValues(); ?

adrianobr commented 8 years ago

I understand, the data values are IDs

<select>
<option value = "1"> One </ option>
<option value = "2"> Two </ option>
<option value = "3"> Three </ option>
</select>

I need the description and not the values. Do you understand?

hamzaouekdi commented 8 years ago

Sorry no idea about that, but if you have access to db you can select them from the bitnami_redmine.custom_fields table. Or maybe you should hardcode it with a standard if else

String desc="";
if (cf.getValue()==1)
    desc="One";
adrianobr commented 8 years ago

ok, I try to access directly to the database. thank you!

hamzaouekdi commented 8 years ago

you are welcome

alexeyOnGitHub commented 8 years ago

sample:

 RedmineManager mgr = RedmineManagerFactory.createWithUserAuth(redmineURI, login, password);
 CustomFieldManager customFieldManager = mgr.getCustomFieldManager();
 List<CustomFieldDefinition> list = customFieldManager.getCustomFieldDefinitions();

I added this to CustomFieldManager javadoc