How to add condition in custom field

In custom field, can we add below evalutaion condition ?

if 55 < TotalCustomField1 < 80 = 1.5

If 30 < TotalCustomField1 < 55 = 3.5

If TotalCustomField1 < 30 = 4

i went through below link, but i could not found as above how i want:

https://innovalog.atlassian.net/wiki/display/JMCF/JIRA+Misc+Custom+Fields#JIRAMiscCustomFields-calculatednumberfield

Can we add as below in custom field ?

if((issue.get("customfield_11246") != null ? Integer.parseInt(issue.get("customfield_11246")) : 0) >55 && (issue.get("customfield_11246") != null ? Integer.parseInt(issue.get("customfield_11246")) <80)

{

return 1.5

}

or any alternative solution ?

2 answers

Yes, this would work, assuming the two customfields are text fields or equivalent. If the customfields are numeric fields, you don't need to parse them, and if they are select fields, you'll need to add a getValue() on the result of the get().

when i paste above stuff then unable to see the field in screen..

yes, value is from calculation textbox field only (used in 'if' condition).

0 votes
Henning Tietgens Community Champion Jun 17, 2013

You can also use the free Script Runner plugin and create a scripted custom field with code like yours above.

Henning

can you please correct me if below stuff not work direclty .. then how to fetch custom field value in groovy script runner and based on it's value return the value as above comment example.

if((issue.get("customfield_11246") != null ? Integer.parseInt(issue.get("customfield_11246")) : 0) &gt;55 &amp;&amp; (issue.get("customfield_11246") != null ? Integer.parseInt(issue.get("customfield_11246")) &lt;80)

{

return 1.5

}

Henning Tietgens Community Champion Jun 17, 2013

What kind of field is your customfield?

Henning Tietgens Community Champion Jun 17, 2013

If it's a text custom field, this should work.

def user = componentManager.jiraAuthenticationContext.getLoggedInUser()
Double ret = null

if (componentManager.fieldManager.getAvailableCustomFields(user, issue).find{it.name == 'Custom Field Name'}) {

    try {
        int value = (getCustomFieldValue('Custom Field Name') as String)?.toInteger()
    } catch (NumberFormatException nfe) {
        value = 0
    }
    
    switch (value){
        case {it &lt; 30}: ret = 4.0; break
        case {it &lt; 55}: ret = 3.5; break
        case {it &lt; 88}: ret = 1.5; break
        default: ret = 0.0
    }
}
return ret

Please be aware to choose the matching number templates.

Henning

Thanks @Henning.

actually, this script field is not appearing in the screen where asscoiated.

it shows in "where is my field" when i do it on edit screen but not appear in the screen. what can be the cause..

jira stand alone version - 5.2.11

my custom field type (whose value in evalutaion) is "calcualted custom field"

Henning Tietgens Community Champion Jun 18, 2013

Scripted fields will only be displayed on the view screen because they are not editable.

I don't know which kind of object the customfield value of a "calculated custom field" is. If the script throws exceptions you may hav to look at the class of the return value from getCustomFieldValue().

log.error getCustomFieldValue('Custom Field Name')?.class?.name

print the class name of the object to the log file.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

122 views 6 8
View post

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