Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add condition in custom field

dhaval soni
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.
June 17, 2013

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

0 votes
Henning Tietgens
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.
June 17, 2013

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

Henning

dhaval soni
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.
June 17, 2013

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
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.
June 17, 2013

What kind of field is your customfield?

Henning Tietgens
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.
June 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

dhaval soni
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.
June 18, 2013

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

0 votes
David Fischer June 17, 2013

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

dhaval soni
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.
June 17, 2013

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events