A number of projects use the same set of workflows, and we plan to keep it that way to stop divergence. One team has asked that the field Story Points is mandated in a transition for their project, so I have tried to add a validator, as below;
import com.atlassian.jira.issue.Issue
def sp = customFieldManager.getCustomFieldObjectByName("Story Points")
if ( issue.projectObject.key == 'MAP' || issue.projectObject.key == 'DIGTST' && issue.getCustomFieldValue(sp).toString() == null ) {
return false;
}
The problem is that regardless of the content of Story Points (empty, 0 or a value > 0) it always returns false. I realise that this statement is totally incorrect (not least because Story Points should be an integer)
issue.getCustomFieldValue(sp).toString() == null
I have also tried this method
cfValues['Story Points'] == ''
But get the same results
Any thoughts?
Three thoughts:
Instead of using ==, try the java .equals('MAP') construct - strings compared with == aren't always the same, even when they have the same content!
cfValues['Story Points'] should return a number, if memory serves, so try swapping the == '' to > 0
The other thought is to re-check your "if" statement - it currently says "if project 1 or project 2 and value is" - I think you probably want "if (project 1 or project 2) and value is"
Thanks Nic for the direction. I have finally found the solution from various sources, this is the completed code (which I am sure would shame me and Groovy coders are biting at the bit to improve :-))
if ( issue.projectObject.key == 'MAP' || issue.projectObject.key == 'DIGTST' ) {
if ( ( ( cfValues['Story Points'] ?:0 ) as Integer ) <= 0 ) {
return false;
}
}
return true;
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.