I am a starter with scripting. I need to add a validation at a transition where if the resolution is "Fixed" and a field called "Defect Flags" (multi-select Check box) has "regression" chosen as one of the value, then another field called "Regression Introduced By" (Cascading field) should not be empty and a validation error message needs to be thrown.
I tried adding this script, any help on this?
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import java.text.SimpleDateFormat
import java.util.*
import java.sql.Timestamp
ComponentManager componentManager = ComponentManager.getInstance()
//CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//issue = componentManager.getIssueManager().getIssueObject("CAN-9829")
CustomField resolution = customFieldManager.getCustomFieldObjectByName("Resolution");
Object resolutionValue = resolution.getValue(issue);
CustomField DefectFlag = customFieldManager.getCustomFieldObjectByName("Defect Flags");
Object DefectFlagValue = DefectFlag.getValue(issue);
CustomField RegressionIntroducedBy = customFieldManager.getCustomFieldObjectByName("Regression Introduced By");
Object RegressionIntroducedByValue = RegressionIntroducedBy.getValue(issue);
if ((resolutionValue == "Fixed") && (DefectFlagValue.equals("Regression")) && (RegressionIntroducedByValue.equals("None")) )
{ error message here }
You can add this as a custom script validator with the following script:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.customfields.option.Option import com.opensymphony.workflow.InvalidInputException def issue = issue as Issue def customFieldManager = ComponentAccessor.getCustomFieldManager() def detectFlagsField = customFieldManager.getCustomFieldObjectByName("Defect Flags") def introducedByField = customFieldManager.getCustomFieldObjectByName("Regression Introduced By") def detectFlagsValue = issue.getCustomFieldValue(detectFlagsField) as List<Option> def introducedByValue = issue.getCustomFieldValue(introducedByField) if (issue.resolution?.name == "Done" && detectFlagsValue*.value?.contains("Regression") && ! introducedByValue) { throw new InvalidInputException(introducedByField.id, "Must have introduced by!") }
First we get the custom fields then get the values for the custom fields and the check each one along with the resolution. The cascading select will be null if none is selected and introduced by may contain a list of options so will check it contains "Regression".
Finally if all conditions pass then we throw an InvalidInputException to prevent the user submitting the form and it will show an error message next to the "Regression Introduced By" field.
Hope this helps,
Adam
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.