Error on Custom-field Configuration page, not able to set default value

Nitinraj August 28, 2020

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.

CustomField error.PNG

 

 

Best Regards,
Nitinraj

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 28, 2020

hello @Nitinraj can you share your custom field source code?

Nitinraj August 30, 2020

.

Nitinraj August 30, 2020

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)

 
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 31, 2020

@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?

Nitinraj September 1, 2020

@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>
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2020

ok and what about log file?

Nitinraj October 19, 2020

Hi @Martin Bayer _MoroSystems_ s_r_o__ ,

Nothing found in logs

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2020

Hi @Nitinraj there should be something, can you go to configuration page and send share your atlassian-jira.log file?

Nitinraj November 9, 2020

Hi @Martin Bayer _MoroSystems_ s_r_o__ ,

I have fixed problem, thank you so much for looking into it. 

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 9, 2020

Oh great :). Can you share what was the problem? :)

Nitinraj November 9, 2020

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 "

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 9, 2020

Ah, ok, because in the configuration action, you have no issue... good job :)

Like Nitinraj likes this

Suggest an answer

Log in or Sign up to answer