For a given issue type, I have behaviours that show/hide certain custom fields on the edit screen based on certain conditions. These custom fields are not marked as "Required" . On the resolve issue screen, I am adding a workflow validator to make certain fields mandatory based on the resolution that's being picked. A subset of custom fields will get checked, if they're not hidden and have null values, I'll throw an exception. Is there a way to find out if a certain custom field is visible or not. Sample code below for illustration:
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
//Don't bother with duplicate resolution
if (issue.getResolution().getName()=="Duplicate") {
return
}
InvalidInputException errEx = null
List<String> myCFs = ["CF-name1","CF-name2",...."CF-nameN"]
for (int i = 0; i < N; i++) {
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(myCFs[i])
IF ( ***CHECK IF CF IS HIDDEN OR NOT***) {
String cfVal = issue.getCustomFieldValue(cf)
if (cfVal == null || cfVal.isEmpty()) {
if (errEx == null) {
errEx = new InvalidInputException (myCFs[i] + " must have a value")
} else {
errEx.addError(myCFs[i] + " must have a value")
}
}
}
}
}
if (errEx == null) {
return
}
throw errEx