Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve fields default values via REST API's

Mahmoud Mohammad El-Aziz July 30, 2019

Hi,

We are retrieving the fields using this API call baseurl/rest/api/2/issue/createmeta?projectKeys=x&issuetypeIds=x&expand=projects.issuetypes.fields.

We need to retrieve the added default values this API returns all the fields along with this boolean "hasDefaultValue : true" but we can't retrieve the default values.

Is there any additions to params should be added to retrieve default values.

And thanks in advance.

Regard.

1 answer

1 accepted

1 vote
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 2, 2019

Hi Mahmoud,

If I understand your request here, you are looking to use the REST API in Jira to find the default values that some fields can have.   I believe that the endpoint you are calling here, with the expand options, is actually the correct way todo this.   I was able to follow these same steps to find this in my test instance where I know I have a custom field with a default value set:

"customfield_10094":{
"required":false,"schema":
{"type":"array","items":"option","custom":"com.atlassian.jira.plugin.system.customfieldtypes:multiselect","customId":10094},
"name":"selectM","key":"customfield_10094","hasDefaultValue":true,"operations":["add","set","remove"],"allowedValues":[{"self":"https://[examplecloudsite].atlassian.net/rest/api/2/customFieldOption/10115","value":"hello","id":"10115"},
{"self":"https://[examplecloudsite].atlassian.net/rest/api/2/customFieldOption/10116","value":"goodbye","id":"10116"}],
"defaultValue":[{"self":"https://[examplecloudsite].atlassian.net/rest/api/2/customFieldOption/10115","value":"hello","id":"10115"}]
}

To find this I used a text editor, sublime, that let me search with a regex of

hasDefaultValue":true[A-Za-z0-9\/\:\"\[\]\{\}\_\,\.]*"defaultValue":

The defaultvalue entry there then has a value that represents the actual default value for that field.   In the case of my example, that select field has only two options called "hello" and "goodbye" in this example, "hello" is the default value.

However in looking into this problem I found that the documentation on using this REST API endpoint does make a few notes about using expand here:

expand

string

Use expand to include additional information about issue metadata in the response. This parameter accepts projects.issuetypes.fields which returns information about the fields in the issue creation screen for each issue type. Fields hidden from the screen are not returned

It's that past part that could trip you up here.  It is very possible that the field in question here has a default value set for it, but that field is not listed on the screen.  When this happens the end user can't see that field at all anyways.  This tends to happen when a field is marked as required by the field configuration scheme, but a Jira Admin wants to keep that field out of the view of the end user.  In cases like this those fields have to use a predetermined defaultvalue just so that the issue can be created.   But since the end user is not expected to even be able to see the field, then in cases like this, the REST API can't return default values for fields that do not appear on the screen itself.

I hope this helps.

Andy

Suggest an answer

Log in or Sign up to answer