Hi dear community,
I have encountered a bug, where, if I access a custom field using issue.getCustomFieldValue in a Validator, I will get a NULL value for calling the same in a post-function in the same transition.
Let me start by explaining our usecase first:
A validator checks if all the comma separated project keys provided in a field are valid:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
def projectManager = ComponentAccessor.getComponent(ProjectManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfProjectName = customFieldManager.getCustomFieldObject(16610)
List < String > projectKeys = (List) issue.getCustomFieldValue(cfProjectName).split(",").collect()
if (issue.getSummary().contains("Bulk Action")) {
for (projectKey in projectKeys) {
def project = projectManager.getProjectObjByKey(projectKey.trim().toUpperCase())
if (!project) {
return false
}
}
}
return true
After which, a post-function is supposed to create sub-tasks for each project key included in that field:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def projectManager = ComponentAccessor.getComponent(ProjectManager)
def cfProjectName = customFieldManager.getCustomFieldObject(16610)
def cfRequestType = customFieldManager.getCustomFieldObjectsByName("Request type")[0]
def requestType = issue.getCustomFieldValue(cfRequestType)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
List < String > projectKeys = (List) issue.getCustomFieldValue(cfProjectName).split(",").collect()
if (issue.getSummary().contains("Bulk Action")) {
for (projectKey in projectKeys) {
def newSubtask = ComponentAccessor.getIssueFactory().getIssue()
newSubtask.setSummary("Customization Request for " + projectKey.trim().toUpperCase())
newSubtask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find {
it.getName() == "Sub-task"
}.id)
newSubtask.setProjectId(issue.getProjectId())
newSubtask.setParentId(issue.getId())
newSubtask.setReporterId(issue.getReporterId())
newSubtask.description = issue.getDescription()
newSubtask.setCustomFieldValue(cfRequestType, requestType)
newSubtask = issueManager.createIssueObject(user, newSubtask)
subTaskManager.createSubTaskIssueLink(issue, newSubtask, user)
}
}
If the validator is not in place, this code works without an issue. Hoowever, if the validator is installed (which also works correctly for validating the project keys), the post-function stops working, and gives this error:
java.lang.NullPointerException: Cannot invoke method split() on null object
2024-07-16 08:52:44,923 ERROR [utils.ConditionUtils]: Workflow condition script has failed for user 'username'. View here: https://jiraurl/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=workflowname:+Workflow+for+Requests&descriptorTab=validators&workflowTransition=1&highlight=2
java.lang.NullPointerException: Cannot invoke method split() on null object
at java_lang_String$split$6.call(Unknown Source)
at Script853.run(Script853.groovy:8)
Anyone knows why accessing the field at the validator breaks access at post-function, and if there's a fix or a workaround for this?
P.S I've tried both vanilla scriptrunner validator and JWME app validator, with the same result.