Hello would like to enable behaviors for a bug Issue type that meets the following two conditions on the Resolve screen before the user can transition to Done.
Environment (custom field) = Production
Story Points (system field) = Is not null (i.e greater than zero)
If the environment is not production, don't require story points and allow to transition.
If the environment is production, require story points to be greater than 0 to transition.
Here is the script I've been trying to create based on research, but the setRequired portion is not working. Any suggestions would be greatly appreciated.
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fieldEnv = customFieldManager.getCustomFieldObjectByName ("Environment")
def fieldEnvValue = getCustomFieldValue(fieldEnv)
def fieldSp = customFieldManager.getCustomFieldObjectByName ("Story Points")
def fieldSpValue = getCustomFieldValue (fieldSp)
if (fieldEnvValue == "Production" && fieldSpValue != null) {
fieldSp.setRequired(true)
UserMessageUtil.success('Add some points! ')
}else{
fieldSp.setRequired(false)
}
Ahh, found a similar question and believe I have this solved. Using the following:
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def envField = getFieldById(getFieldChanged())
def fieldEnv = getFieldByName ("Environment")
def spField = getFieldByName("Story Points")
String fieldEnvValue = fieldEnv.getValue()
String spIssueValue = spField.getValue()
if (fieldEnvValue == "Production" && spIssueValue != null) {
spField.setRequired(true)
} else {
spField.setRequired(false)
}
So this works for having a null value in the Story Points field but not if the value is 0.
I would like it have a number greater than 0. I tried to set my spFieldValue to integer but it's throwing errors. Any thoughts out there?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Justin,
Casting String to Int should work. The following code may guide you.
int spIssueInt = Integer.parseInt(spIssueValue);
if(spIssueInt == 0){
spField.setError("SP must be greater than 0")
} else{
spField.clearError()
}
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.