I've got a script that automatically creates a subtask for each value of the field Environment. This works out great.
However, I want that script to only do it's job if the value of another field (Release) equals 'yes'. And here is where it goes wrong. The value of the field 'Release' is retrieved and it does equal 'yes', but it does not actually create the subtasks anymore.
What am I missing here?
In order below:
- The original script
- The addition that doesn't work
- The log
Original script:
// Imports
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.priority.Priority
// import for debug only
import org.apache.log4j.Logger
import org.apache.log4j.Level
log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
//Current issue - uncomment for post-function
Issue parentIssue = issue
//Get Value of Environment
CustomFieldManager cFM = ComponentAccessor.getCustomFieldManager()
String Environment = 'customfield_12090'
CustomField customfield_Env = customFieldManager.getCustomFieldObject(Environment)
Object customfieldIDValue_Env = (ArrayList) parentIssue.getCustomFieldValue(customfield_Env)
//Pre-define JQL Parser functions
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def activeUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Pre-define Sub-Task Generation functions
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def dueDate = parentIssue.getDueDate()
def project = parentIssue.getProjectObject()
def description = parentIssue.getDescription()
def priority = parentIssue.getPriority()
def component = parentIssue.getComponents()
def reporter = parentIssue.getReporter()
//Iterate through and create subtasks
for (int i = 0; i < customfieldIDValue_Env.size(); i++){
def summary = "Release subtask - " + customfieldIDValue_Env.get(i)
def environment = customfieldIDValue_Env.get(i)
//Create core Sub-Task Values
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setProjectObject(project)
newSubTask.setReporter(reporter)
if (issue.projectObject.key == 'CICD') {
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Simplified Release"}.id)
} else {
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Release subtask"}.id)
}
newSubTask.setParentObject(parentIssue)
newSubTask.setSummary(summary)
newSubTask.setDescription(description)
newSubTask.setDueDate(dueDate)
newSubTask.setComponent(component)
newSubTask.setPriority(priority)
newSubTask.setReporter(activeUser)
//Create Sub-Task
def newIssueParams = ["issue" : newSubTask] as Map
def createdSubTask = issueManager.createIssueObject(activeUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, createdSubTask, activeUser)
}
This works really well.
If I add this to the script above, it fails:
//Get Value of Release
def release = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_17205")
def releaseValue = issue.getCustomFieldValue(release)
log.warn(releaseValue)
//Iterate through and create subtasks
if(releaseValue == "Yes"){
for (int i = 0; i < customfieldIDValue_Env.size(); i++){
def summary = "Release subtask - " + customfieldIDValue_Env.get(i)
def environment = customfieldIDValue_Env.get(i)
...
}
Value of the Release field:
