JIRA Plugin custom field multi select

hi dear community,

I have write a custom field which get values from an external SQL database and read it in a multi selected custom field.

If I set a value to the custom field all is working fine, but there is a problem if I move the Issue to a another project the value is still exist in the new issue, although it doesn't have values in the other project. 

The database query select our available teams for a specific project.

 

 

public class FunctionalTeamCF extends GenericTextCFType

{

    private static Connection conn;

    private static Statement statement;

    

 

    protected FunctionalTeamCF(CustomFieldValuePersister customFieldValuePersister,

            GenericConfigManager genericConfigManager,

            TextFieldCharacterLengthValidator textFieldCharacterLengthValidator,

            JiraAuthenticationContext jiraAuthenticationContext) {

        super(customFieldValuePersister, genericConfigManager, textFieldCharacterLengthValidator, jiraAuthenticationContext);

    }

    

    @Override

    public Map getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem)

    {    

        Map map = new HashMap();

        Map<String, String> results = new HashMap<String, String>();    

 

        //aktuelles Issue Projekt

        String project = issue.getProjectObject().getKey();            

        results = getValues(project);;

        

        if(!results.isEmpty() && results != null)

        {

            map.put("results", results);

        }

        else

        {

            map.put("results", "None");

        }

        return map;

    }

 

I suspect that the velocity template file edit.vm makes the problems..

 

#* @vtlvariable name="results" type="java.util.Map" *#
#controlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters.noHeader)

    #if($value && !$value.equals(""))
    #set ($displayValue = ${value})
    #end    
    
    #if($results && !$results.equals("") && !$results.empty)
        <select class="text long-field" name="$customField.id" id="$customField.id" >
           <option value="">None</option>
           #foreach ($mapEntry in $results.entrySet())
                <option value="$mapEntry.key">$mapEntry.value</option>
           #end
        </select>  
    #else
        <select class="text long-field" name="$customField.id" id="$customField.id" >
            <option value="">None</option>
        </select>
        #set ($Value = "")
     #end

#controlFooter ($action $fieldLayoutItem.fieldDescription $displayParameters.noHeader)

2 answers

Hi 

Your code will read the value and store it in the JIRA database, however it will not refresh that value when you move the issue to another project. So you need to understand that once the value is stored it will not be updated as a "live value" until your code is executed again. 

Depending on how frequently you move issues it may be worthwhile having a "refresh values" step in your workflow for those times when you need to update that would execute your code and store the values pulled at that time. These would then use the parameters from the new project rather than the previous project.

Hope this helps

Phill

Is there a specific method in the JIRA SDK which I could use for an issue update in the JIRA database ?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,725 views 17 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you