0

I am new into using Velocity but this is what I am attempting to do.

Based on a issue type "service request" and custom field option 'a' set description to display 'x'

Based on a issue type "service request" and custom field option 'b' set description to display 'y'

Based on a issue type "service request" and custom field option 'c' set description to display 'z'

I have used the following for this

if (($issue.key == '') & ($issue.type().getname == 'service request') & ($customfieldmanager().getcustomfieldoption = '11504') & ($id == 'a'))
set ($description = 'x')

elseif ($id == 'b')
set ($description = 'y')

else ($id == 'c')
set ($description = 'z')

Seems not to recognise the the custom field id or the custom field selection id.

Anyone recommend what could be going wrong here, I have had no luck and have tried a few different ways and have spent a few days attempting to work this out.

Help would be appreciated.

Kiloreux
  • 2,220
  • 1
  • 17
  • 24

1 Answers1

0

For logical "AND" use "&&" instead "&". Please see here: http://velocity.apache.org/engine/devel/user-guide.html#relationalandlogicaloperators

if, else, set should have "#" in front.

if else need "end": https://click.apache.org/docs/velocity/user-guide.html#conditionals

In your sample, issue and customfieldmanager should be in velocity scope. So JIRA (or your JIRA plugin) action should have appropriate getIssue() and getCustomFieldManager() methods and you can access them in velocity as $issue and $customFieldManager (or $getIssue() and $getCustomFieldManager()). Pay attention to cases and brackets. Similar situation with getname and getcustomfieldoption. Please see here: https://stackoverflow.com/a/17069545/1537800

I am not sure about lower/upper cases in method names, but corrected version may look like:

#if ($issue.key == '' && $issue.getType().getName() == 'service request' && $customFieldManager.getCustomFieldOption() == '11504' && $id == 'a')
#set ($description = 'x')

#elseif ($id == 'b')
#set ($description = 'y')

#else ($id == 'c')
#set ($description = 'z')
#end
Community
  • 1
  • 1
  • Hi thank you but this also did not work. How to call a customfieldoption ID so within the database using MySQL I would use: select ID from customfieldoption where customfield = '11504'; to call the 3 options from that customfield. How would I use this in a velocity template so the description changes based on a customfieldi iD selection – user4492681 Feb 07 '15 at 01:36
  • Not sure if this has even been accomplished but is there another way of getting what I am after? – user4492681 Feb 07 '15 at 01:37