Hi Team,
I have developed my own Select list custom-field. It works as expected.
But It is showing some error on the custom-field configuration page because of which I am not able to set the default value. Attaching the screenshot for reference. Please let me know if you need any further details.
Best Regards,
Nitinraj
hello @Nitinraj can you share your custom field source code?
Hi @Martin Bayer _MoroSystems_ s_r_o__ ,
Here is the code:
JAVA:
import java.util.HashMap;
import java.util.Map;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.impl.SelectCFType;
import com.atlassian.jira.issue.customfields.manager.GenericConfigManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.customfields.option.Options;
import com.atlassian.jira.issue.customfields.persistence.CustomFieldValuePersister;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem;
import com.atlassian.jira.issue.fields.rest.json.beans.JiraBaseUrls;
import com.atlassian.jira.issue.search.SearchContextImpl;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.JiraImport;
@Scanned
public class JiraCustomField extends SelectCFType {
public JiraCustomField(@JiraImport CustomFieldValuePersister customFieldValuePersister,
@JiraImport OptionsManager optionsManager, @JiraImport GenericConfigManager genericConfigManager,
@JiraImport JiraBaseUrls jiraBaseUrls) {
super(customFieldValuePersister, optionsManager, genericConfigManager, jiraBaseUrls);
}
@Override
public Map getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem) {
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
Map parameters = super.getVelocityParameters(issue, field, fieldLayoutItem);
FieldConfig fieldConfig = null;
if (issue == null) {
fieldConfig = field.getReleventConfig(new SearchContextImpl());
// System.out.println(“=========fieldConfig if” + fieldConfig);
} else {
fieldConfig = field.getRelevantConfig(issue);
// System.out.println(“======fieldConfig else” + fieldConfig);
}
Options options = optionsManager.getOptions(fieldConfig);
// if (options.isEmpty()) {
// optionsManager.createOption(fieldConfig, null, new Long(1), "Option-One");
// optionsManager.createOption(fieldConfig, null, new Long(2), "Option-Two");
// }
//
//
// options = optionsManager.getOptions(fieldConfig);
Map<Long, String> results = new HashMap<Long, String>();
Long selectedId = (long) -1;
Long sequenceId=(long) -1;
boolean selected = false;
Object value = field.getValue(issue);
// System.out.println("== value" + value);
if (value != null) {
selected = true;
}
for (Option option : (Iterable<Option>) options) {
results.put(option.getOptionId(), option.getValue());
if (selected && value.toString().equals(option.getValue())) {
selectedId = option.getOptionId();
sequenceId= option.getSequence();
// System.out.println("selectedId======== : " + selectedId);
}
}
// System.out.println(“==results== : “ +results);
parameters.put("results", results);
parameters.put("selectedId", selectedId);
parameters.put("sequenceId", sequenceId);
return parameters;
}
}
Edit VM file:
#disable_html_escaping()
#customControlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters $auiparams)
#* @vtlvariable name="results" type= "java.util.Map" *#
#* @vtlvariable name="selectedId" type="java.lang.String" *#
<select name="$customField.id" id="$customField.id" class="select" >
#if (!$fieldLayoutItem || $fieldLayoutItem.required == false)
<option value="-1">None</option>
#else
#if ( !$configs.default )
<option value="">None</option>
#end
#end
#foreach ($mapEntry in $results.entrySet())
#if ( $selectedId == $mapEntry.key )
<option selected="selected" value="$mapEntry.key">$mapEntry.value</option>
#else
<option value="$mapEntry.key">$mapEntry.value</option>
#end
#end
</select>
#customControlFooter ($action $customField.id $fieldLayoutItem.fieldDescription $displayParameters $auiparams)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nitinraj I can't find "zoi-Colorselectfield" in your source code but it must be somewhere. What is printed to you atlassian-jira.log file when custom field configuration is displayed with this error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Martin Bayer _MoroSystems_ s_r_o__ ,
"zoi-Colorselectfield" is in atlassian-plugin.xml file as name:
<customfield-type name="Jira ColorCode SelectList Custom Field" i18n-name-key="color-selectField.name" key="zoi-Colorselectfield" class="com.karcher.zoi.jira.customfields.JiraCustomField.JiraCustomField">
<description>A Custom Select List field with color(ZOI)</description>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok and what about log file?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nitinraj there should be something, can you go to configuration page and send share your atlassian-jira.log file?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Martin Bayer _MoroSystems_ s_r_o__ ,
I have fixed problem, thank you so much for looking into it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh great :). Can you share what was the problem? :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have to make changes in the above java code:
if (issue == null) {
//fieldConfig = field.getReleventConfig(new SearchContextImpl());
return parameters;
// System.out.println(“=========fieldConfig if” + fieldConfig);
}
Return parameters instead of "fieldConfig "
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, ok, because in the configuration action, you have no issue... good job :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.