cancel
Showing results for
Did you mean:
See all
See all
##### Groups
Explore all groups

# 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

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;```

#### 1 accepted

1 vote

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?

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.

```&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

Issue has been resolved. the correct formula was:

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

Community showcase
Published Mar 13, 2019 in Marketplace Apps

### Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page

&nbsp...

249 views 0 6

### Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

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.