I'm trying to compare to numbered fields and want to throw a specific text when the one field are 2 numbers or less away from the other field. I tried with a scripted field to do below but it will not accept the minus i have after field 2
-------------------
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def Field1 = customFieldManager.getCustomFieldObject(00001);
def Field2 = customFieldManager.getCustomFieldObject(00002);
def TFTR = issue.getCustomFieldValue(Field1);
def EH = issue.getCustomFieldValue(Field2);
if (EH <= TFTR - 2) return "Some text 1";
else return "Some text 2";
--------------------
Hope someone can help
This should work, obviously you have to adapt the value you want in case the fields are null
def TFTR
def EH
if (issue.getCustomFieldValue(Field1) !=null) TFTR = (int) issue.getCustomFieldValue(Field1);
else TFTR = 0;
if (issue.getCustomFieldValue(Field2) !=null) EH = (int) issue.getCustomFieldValue(Field2);
else EH = 0;
if (EH <= (TFTR - 2)) return "Some text 1";
else return "Some text 2";
Thanks @fran garcia gomera now i have no errors in the script but it just returns null - no text - any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which are the values of the fields in the issues you are trying?
the final if/else should always return a text unless there is an error before that returns the null. Try adding logs to see the values of the variables before the if and to check if they go into the if/else properly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Do you have anything more specific about the error?
I think you could try converting your value to integer this way :
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def Field1 = customFieldManager.getCustomFieldObject(00001);
def Field2 = customFieldManager.getCustomFieldObject(00002);
def TFTR = issue.getCustomFieldValue(Field1).toInteger();
def EH = issue.getCustomFieldValue(Field2).toInteger();
if (EH <= (TFTR - 2)) return "Some text 1";
else return "Some text 2";
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for chipping in @Arthur SALMON i just tried the convert to integer that you sugested, but without success. The error i get from script is below - hop you will be able to assist based on that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think this code should do the trick :
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def Field1 = customFieldManager.getCustomFieldObject("customfield_00001");
def Field2 = customFieldManager.getCustomFieldObject("customfield_00002");
def TFTR = (int)issue.getCustomFieldValue(Field1);
def EH = (int)issue.getCustomFieldValue(Field2);
if (EH <= (TFTR-2)) return "Some text 1";
else return "Some text 2";
Just replace the 00001 & 00002 with the id of your custom field. You can find it when you click on "configure" on the custom field in the url address.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tested it and it worked fine for me, that is weird. Did you set the (int) in your def TFTR & def EH ?
Both your field are "number fields" ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Both fields are numbered fields but "field1" is also scripted from an external DB
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It could be the reason why.
You should try to set up logs or check directly on Jira if you have more specific errors. I can't help on that, I haven't done it yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.