How can i access the particular customfield fields value like I want to get approver field accountId value then how can we access that.
Hi,
Basically, what the rest call resturn is a JSON response.
First, try and do the call in Postman or another client where you can inspect the result.
The response might look something like this for the Approvers field:
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id": "10083",
"self": "https://<your-site>.atlassian.net/rest/api/3/issue/10083",
"key": "AUTBL-26",
"fields": {
"customfield_10003": [
{
"self": "https://<your-site>.atlassian.net/rest/api/3/user?accountId=557058%3Afbb39111-6fb5-4fa3-acca-2807f563c6df",
"accountId": "<the account ID here>",
"emailAddress": "someEmail@email.com",
"avatarUrls": {
"48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:fbb39111-6fb5-4fa3-acca-2807f563c6df/55d30f27-0da5-45da-a670-91e420673421/48",
"24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:fbb39111-6fb5-4fa3-acca-2807f563c6df/55d30f27-0da5-45da-a670-91e420673421/24",
"16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:fbb39111-6fb5-4fa3-acca-2807f563c6df/55d30f27-0da5-45da-a670-91e420673421/16",
"32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:fbb39111-6fb5-4fa3-acca-2807f563c6df/55d30f27-0da5-45da-a670-91e420673421/32"
},
"displayName": "Jeroen Poismans",
"active": true,
"timeZone": "Europe/Brussels",
"accountType": "atlassian"
}
]
}
}
As you can see the Approvers field returns an array of objects. So let's try this:
def customfields1 = customFields[0].accountId
Hope this points you in the right direction!
Jeroen
yes i tried in this way too but in post-function script runner it shows warning like this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, never mind the type error and lines ... Those are probanly there because of type checking.
I saw an error in my code, try something like this:
def customfields1 = customFields.fields.customfield_10507[0].accountId
Regards,
Jeroen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No Jeroen there is still type checking errors exist
btw why you are accessing 0th index of array object however the approver field account id is at first index i think.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Never mind the type checking warnings, try executing the code (maybe in script console with an example issue) and see what real errors come out of it then ...
Now, if you inspect the JSON from my first reply you will see that the customfield contains an array. Inside that array the first Approver object is at index 0, not 1.
Regards,
Jeroen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this, this I have tested myself:
def result = get('/rest/api/2/issue/{issue.key}?fields=customfield_10507')
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
return result.body.fields?.customfield_10507[0].accountId
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}
It's the part after the return statement that contains the data you want.
Regards,
Jeroen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.