Accessing a custom field value in velocity file from a java class

Jlamb250194 May 4, 2017

Hi All, 

I have created a couple of custom fields. 

One is a TextCFType field, the other is a SelectCFType.

These are both rendered on create new issue page. 

 

My Goal:

Each time the TextCFType field value changes due to user input, I would like to pass the new value at runtime into a method located in a java class. Lets call this: Example.java. This method will then use the value typed into the TextCFType field to query an external database. Once the results have been returned from this query I would like to populate the SelectCFType with these options. 

When new user input is created, I would like to completely overwrite the options within the SelectCFType. 

 

My Issue:

Having come from a Java and c# background I am not very familiar with javascript and client side programming. I do not know how to access the value of my TextCFType field each time the value is changed from my Java Method. 

 

So far I create a velocity variable at initialization called: $example.

This variable contains an instance of my Example class with several methods.

I have managed to add an "onChange" event to my TextCfType field so that when the user input is changed the following javascript function is called:

function calculateSelectOptions(){
var e = document.getElementById("$customField.id");
var text = e.options[e.selectedIndex].text;

$example.updateSelectOptions(text);

 

}

When this method is called nothing happens. It does not seem as though I am able to pass the value of "text" to my method.

I have tried several different options including using a one of the setter methods of my Example class to change the 'value' attribute of the class with an external listener listening for changes in this variable. Nothing seems to work. 

 

Could someone please provide some guidance (or even better... a solution) on how this is achievable. 

1 answer

0 votes
Frank Curran March 28, 2018

@Jlamb250194, any luck with this?

Suggest an answer

Log in or Sign up to answer