Calculate field number based on Select list (if statement)

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

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

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?

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 [....]

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"

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;

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

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.

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;

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

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

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.

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

The plugin is not correctly installed.

What version of JIRA and of JMCF are you using?

JIRA v6.0.4
JMCF 1.5.7

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

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).

Issue has been resolved. the correct formula was:

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

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

187 views 0 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