Hi,
I want to get some custom field values, but I reference to the custom field name with variables, this is my current code:
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body as Map
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def cf = "PS1N1"
def cf_id = customFields.find { it.name == cf }?.id
return issue.fields.cf_id
I want to get the value from "issue.fields.customfield_12345" but I need the 12345 to be variable because I'm planning to have all the custom fields I need to check with a loop.
Any ideas?
Answering my own question, this is the solution:
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body as Map
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def cf_fields = ["PS1N1", "PS1N2", "PS1N3"]
for (field in cf_fields){
def cf_id = customFields.find { it.name == field }?.id
logger.info(issue.fields.get(cf_id).toString())
}
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.