During the issue creation process, I want to force a user to attach at least one file if the value in a particular custom field has a specific value. However, during the validation, the issue hasn't been created yet, so the custom field doesn't technically have the value during the validation.
I'm using the Scriptrunner custom scripted validator. I am able to get it working if I don't care about the value in the custom field (i.e. it ALWAYS requires an attachment), but I can't figure out how to write the condition into the script.
Octopus Update Type is the custom field name and I want to require an attachment if the value of that field is Octopus Variable Update. Below is the script (I apologize in advance for the formatting, I don't remember how to make it a code block)
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.component.ComponentAccessor
def numIssues = ((MutableIssue) issue).getModifiedFields().get(IssueFieldConstants.ATTACHMENT).getNewValue() as Collection<Long>
def octUpdateTypeField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Octopus Update Type").first()
def octUpdateValue = issue.getCustomFieldValue(octUpdateTypeField)
if (octUpdateValue != "Octopus Variable Update") {
return true;
}
if (octUpdateValue == "Octopus Variable Update" && (numIssues.size() == 0 || numIssues == null)) {
invalidInputException = new InvalidInputException("There must be at least one attachment.")
}