I have some groovy code cobbled together that can look at an existing Jira Issue and extract the value of a custom field. Seems to work OK (code segment below):
...
// Fetch the issue object from the key
def issue = get("/rest/api/3/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
// Get all the fields from the issue as a Map
def fields = issue.fields as Map
// Get the Custom field to get the option value from
def customField = get("/rest/api/3/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Cost Centre'
} as Map
// Extract and store the option from the custom field
def costCentreValue = (fields[customField.id] as Map)?.value
...
I take that same code as a Workflow Post Function when creating a Jira Issue and it fails. I'm pretty sure that the fields variable (underlined above) is incomplete for some reason (based on logger.info) and so the costCentreValue ends up being NUL.
The overall idea is to inspect the Cost Centre value and assign the Issue to the appropriate assigneeId.
Can anyone point me in the right direction or explain why, as a Workflow Post Function, the code fails?