Calculate field number based on Select list (if statement)

EL October 21, 2013

Hi every one

It may sound like a simple question for you guys.

I would like to calculate value based on a simple select list:

If Select list value1= A, return 1

If Select list value2= B, return 2

Any advide please?

I was given this formula (thanks) but it does not return any data


if (issue.get("customfield_12345")==null)
  return null;
if (issue.get("customfield_12345").getValue().equals("A"))
  return 1;
if (issue.get("customfield_12345").getValue().equals("B"))
  return 2;

13 answers

1 accepted

1 vote
Answer accepted
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 21, 2013

The @@Format annotation is for formatting the value. You want the @@Formula annotation for the formula that computes the value.

Miguel De Dios January 28, 2014

David,

Is it possible to do this with a range using the Calculated Text Field

So for instance..

<!-- @@Format:
if (issue.get("customfield_10104")==null)
return null;
if (issue.get("customfield_10104").getValue().compareTo(range 0 - 1.75)
return XS;
if (issue.get("customfield_10104").getValue().compareTo(range 2 - 4.75)
return S;
The custom field we want to it to pull in is the "Original Estimate" (use this customfield's ID in formula) so if we estimate .5h then this new field (calculated text field) called "T-Shirt Size" would automatically change into "XS" for Xtra Small

Does this make sense and is this possible?

David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 28, 2014

Sure. But first, you want to create the formula in @@Formula, not @@Format (which is used to customize the formatting of Calculated Number fields).

Then, you could simply assign the field value to a variable and then use a cascade of "if" comparisons. But I don't understand why you're reading customfield_10104 when you're actually trying to use the "Original estimate" field.

In essence, you could do something like:

var = issue.get("customfield_10104")
if (var &gt;= 2.0 and var &lt;= 4.75)
  return "S";
if [....]

0 votes
EL October 23, 2013

Issue has been resolved. the correct formula was:

&lt;!-- @@Formula: 
if (issue.get("customfield_10401").equals("A5"))
return 1;
--&gt;

0 votes
EL October 23, 2013
0 votes
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

Can you raise a support request on our issue tracker: https://innovalog.atlassian.net

Please attach your full atlassia-jira.log. Something must be preventing the plugin from loading (look for ERROR in your logs).

0 votes
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2013

The plugin is not correctly installed.

What version of JIRA and of JMCF are you using?

EL October 23, 2013

JIRA v6.0.4
JMCF 1.5.7

I uninstalled and reinstalled the plugin several times by using the Jira add-ons manager

0 votes
EL October 22, 2013
com.innovalog.jmcf.jira-misc-custom-fields:calculated-number-field'. Is the plugin present and enabled?
2013-10-23 16:05:33,026 Thread-653 ERROR EDZELADIN 965x8262x1 1y9lz28 172.16.255.142,192.168.128.40 /rest/plugins/1.0/com.innovalog.jmcf.jira-misc-custom-fields-key [jira.issue.managers.DefaultCustomFieldManager] Could not load custom field type plugin with key '

This error matchs

0 votes
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2013

Any error in atlassian-jira.log? Please verify the timestamp to match the error with the display of a Jira issue page that should display the calculated field.

0 votes
EL October 22, 2013

Sorry I copied the code from my previous post.

The result is the same with "@@Formula"

For me it looks like issue.get("customfield_10104").getValue().equals("value")) does not work.

Anyway, thanks for support

0 votes
EL October 22, 2013

thanks for support, I followed all your instructions but without success. The issue remains, no returned data.

Are we sure about this formula?

&lt;!-- @@Format:
if (issue.get("customfield_10104")==null)
  return null;
if (issue.get("customfield_10104").getValue().equals("A5"))
  return 1;

David Fischer October 22, 2013

I haven't tried that formula. But again, it should be @@Formula, not @@Format!

0 votes
EL October 22, 2013

Thank you David

I check the Jira.log file and found this

com.innovalog.jmcf.jira-misc-custom-fields:calculated-number-field'. Is the plugin present and enabled?
2013-10-22 17:08:57,017 Thread-1293 ERROR

The plugin is present and enabled, by the way, another calculated number field is present on the same screen (simple addition which works great)

Thanks for support

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 22, 2013

This must have happened at a moment when you were re-installing the plugin. Check the timestamp.

If it keeps on happening, uninstall then reinstall the plugin.

0 votes
EL October 21, 2013

Hi David

Yes I replaced the custom field number and it is a calculated Number field.

I am scanning the log file right now

this was my simpe example

&lt;!-- @@Format: 
if (issue.get("customfield_10104")==null)
  return null;
if (issue.get("customfield_10104").getValue().equals("A5"))
  return 1;
--&gt;

0 votes
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 21, 2013

Naturally you replaced "customfield_12345" with the actual custom field id?

Also, which calculated field type are you using?

You can find out what the problem is by looking at your log file (atlassian-jira.log). Look for "com.innovalog.jmcf"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events