Hello.
I am quite new to JIRA development and after days of searching the forums and JIRA Documentation, I have been unable to find any help.
What I want to achieve is retrieving information from my JIRA instance on "Create Issue" screen (especially User Properties and User Role on a Project) in my Velocity Template file (to store them in a hidden text HTML tag), and being able to use them through JavaScript. All of this to make a JavaScript run through a CustomField plugin described below in xml.
<customfield-type name="Working Custom Field JS" i18n-name-key="working-custom-field-js.name" key="working-custom-field-js" class="com.atlassian.tutorial2.jira.customfields.WorkingCustomFieldJS"> <description key="working-custom-field-js.description">Working Custom Field</description> <resource type="velocity" name="edit" location="templates/plugins/fields/edit/edit-hiddenjs.vm"/> </customfield-type>
I only succeeded in getting Project attributes.
Is there anywhere I can find which variables are available to Velocity Templates?
Am I doing it the right way?
#disable_html_escaping() TODO REENABLE #customControlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters $auiparams) <input class="text" type="hidden" id="currentProject" value="$issue.getProject().getString("name")" /> ## or ##<input class="text" type="hidden" id="currentProject" value="$!issue.projectObject.name" /> #customControlFooter ($action $customField.id $fieldLayoutItem.fieldDescription $displayParameters $auiparams)
I am using JIRA 5.1 by the way.
Thank you.
Community moderators have prevented the ability to post new answers.
is it wt your looking for
https://confluence.atlassian.com/display/JIRA042/Contents+of+the+Velocity+Context
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the answer but I already have visited this page. Tried a few combinations like this :
<input class="text" type="hidden" id="userRole" value="$remoteUser.getDisplayName" /> <input class="text" type="hidden" id="userRole" value="$remoteUser.getDisplayName()" /> <input class="text" type="hidden" id="userRole" value="$remoteUser.getFullName()" />
Which are in fact methods from the Java JIRA API. Still, it does not get interpreted. And by the way, that link is for JIRA 4.2, I am using 5.1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The second line looks correct to me - $remoteUser.getDisplayName() - I've used
I tend to use {} inside velocity when there are strings and " marks knocking around, to make it clear it's a velocity command. I don't really think it's that, but try "${removeUser.getDisplayName()}" to rule it out.
But, I think the actual problem is going to be that remoteUser is not being exposed to your code. You originally asked about what variables are available in a velocity context, which is the right idea. But the answer is "it depends". A velocity context can have hundreds of variables, or next-to-none. It depends on the code behind it. You get a different set of variables (and objects) exposed, depending on what the template is doing and where it's used.
So, the answer might be that your velocity is fine, but your java behind it is not making a user object available.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok now this is some clear answer, I wasn't sure about that as nothing is really stating it clearly in tutorials!
Is too much to ask for a hint about how to invoke a user-like object in my Java CustomField class (the API is so huge I can't think clearly about what to actually use...)?
Here is what's behind :
package com.atlassian.tutorial2.jira.customfields; import org.slf4j.Logger; ... public class WorkingCustomFieldJS extends GenericTextCFType { private static final Logger log = LoggerFactory.getLogger(WorkingCustomFieldJS.class); public WorkingCustomFieldJS(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager) { super(customFieldValuePersister, genericConfigManager); } @Override public Map<String, Object> getVelocityParameters(final Issue issue, final CustomField field, final FieldLayoutItem fieldLayoutItem) { final Map<String, Object> map = super.getVelocityParameters(issue, field, fieldLayoutItem); if (issue == null) { return map; } FieldConfig fieldConfig = field.getRelevantConfig(issue); //add what you need to the map here return map; } }
Thank you!
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.
Yup, you're nearly there. In your java, where it has the "add what you need" comment, that's (not very clearly for new developers) explaining that you need to put stuff into the "map".
Your Velocity will be handed the contents of the "map" when it's asked to return the html that eventually goes to the user, so you need to add the objects you want to access into the map, then use them in your velocity.
//me: makes industrious rummaging noises in his own code...
Map.put("remoteUser", aUserObject);
Obviously, you'll need to write a spot of java to populate aUserObject with a user. The same principles apply for other objects too, numbers, strings, even lists of other objects (although for lists and arrays, you need to tell velocity to iterate through them)
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.