I have this postfunction script that creates a subtask and then assigns the subtask to different users depending on what is entered in a label custom field.
However it keeps failing, with the cfValue returning null.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.label.LabelManager
import org.apache.log4j.Category
def issueId = issue.getId()
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug: Assign sub-task"
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10284")
def cfValue = issue.getCustomFieldValue(customField) as String
if(("labelstring") in cfValue){
issue.setAssigneeId("person1")
log.info ("Custom field value: " + cfValue)
}
else
{ issue.setAssigneeId("person2")
log.info ("Custom field value: " + cfValue)
log.info ("Custom field: " + customField)}
(I'm leaving the logging in there).
I tried this way too:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.label.LabelManager
import org.apache.log4j.Category
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10284").getIdAsLong()
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
def labelMgr = ComponentAccessor.getComponent(LabelManager)
def labelValue = labelMgr.getLabels(issue, customField)
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "debug: Assign sub-task"
if(("somelabel") in labelValue){
issue.setAssigneeId("person1")
log.info ("Custom field value: " + labelValue)
}
else
{ issue.setAssigneeId("person2")
log.info ("Custom field value: " + labelValue)}
The custom field is returning, just not the value. Not sure if custom label fields require a different method?