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())
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.