Getting the error ReferenceError: $finalResult is not defined to retrieve java var in velocity template

i am trying to retreive the static variable results from my java class into velocity template

case ADDCOMMENT : 
					System.out.print("in switch");
					
					System.out.println("len : "+len);
					String temp = null ;
					String finalcomment ="";
					int i;
					if (len<4)
					{
						
						results=bundle.getString("cli.action.default");
						System.out.println(bundle.getString("cli.action.default"));
}
				
				     
				    	 
				    	 
					   else{
						   System.out.println(str1[2]+"comment"+str1[3]+ "appending" + temp);
						   for(i=3;i<len;i++){
							   finalcomment = finalcomment+" "+str1[i];
							   System.out.println("str1[i]"+str1[i].toString());
							  
							 
						   }
						     results = cli.addComment(str1[2],finalcomment);
						   System.out.println("outpput  "+results);
						  
					   }
					
					break;

i have added getters and setters for resutls

this is my velocity template index.vm I get the error ReferenceError: $finalResult is not defined. Where am i goin wrong? This is a web item plugin

<script Language="JavaScript"> 
var fResult = $finalResult;
alert(fResult);
}
</script>

Logs:
<br><textarea rows="15" cols="10" name="Logs" id="Logs" readonly></textarea>


2 answers

1 accepted

i figured out my issue. I was returning null at one point due to which i was not able to read the java variable in velocity.

WEBACTION:

public class JrmpConfiguration extends JiraWebActionSupport {

   private String webSvnPath;

   public JrmpConfiguration(){
       webSvnPath = "path";
   }
	
   public String getWebSvnPath() {
	  return webSvnPath;
   }

   public void setWebSvnPath(String webSvnPath) {
	  this.webSvnPath = webSvnPath;
   }
}

TABPANEL:

public class JrmpConfiguration extends GenericTabPanel {

private String webSvnPath;

@Override
	protected Map<String, Object> createVelocityParams(
			BrowseVersionContext context) {

		Map<String, Object> contextMap = new HashMap<String, Object>();
        webSvnPath = "path";
		contextMap.put("webSvnPath", webSvnPath);
		return contextMap;
	}
}

Velocity:

<script Language="JavaScript"> 
var fResult = $webSvnPath;
alert(fResult);
</script>

Suggest an answer

Log in or Join to answer
Community showcase
Bridget Sauer
Published Feb 08, 2018 in Agile

Community Showcase: Getting to know Kemal, AUG Leader from Bosnia and Herzegovina

  Cheers to Kemal Bajramovic, our first ever AUG Leader to be Showcased. AUG Leaders are passionate experts who find time in their own busy lives to host Atlassian themed events to share ...

197 views 3 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot