JIRA API: How do I explicitly set a custom field it's default value?

Paul R I'm New Here Dec 05, 2017

I have a JIRA board which has a custom field: customfield_20582 which shows up as 'priority', say, in the UI.

 

It has values 'high', 'medium', 'low' and the default which is 'none'.

 

I have a request to create a new issue like this:

 

POST blah/rest/api/2/issue/

BODY:

    {
        "fields": {
           "project":
           {
              "key": "ABCD"
           },
           "summary": "here is a summary",
            "customfield_20582": {
                "value": "None",
            },
           "description": "here is a description",
           "assignee": {"name": "123456"},
           "reporter":  {"name": "654321"},
           "issuetype": {
              "name": "my issue type"
           }
       }
    }

 

Without the 'customfield_20582' bit - this works perfectly, and i get a response with the newly created Issue key.

 

If I change the 'customfield' bit to 'High', 'Medium' or 'low' it also works fine.

 

But when I try to set the value to be the default 'None' i get issues:

 

   "errors": {
        "customfield_20582": "Option id 'null' is not valid"
    }

 

  "errors": {
        "customfield_20582": "Could not find valid 'id' or 'value' in the Parent Option object."
    }

I've tried:

* "None"

* "Null"

* null

* "-1"

* -1

when I inspect the select element, I see the id is -1 and the value is 'None' - but there must be more to it.

I know if I remove the 'customfield' piece entirely, the default will be used, well, by default - but It would be much easier (because we're using API call templates) to just explicitly specify that it should use the default.

I'd also need to set it back to default later.

 

How can I specify that the default value be set.

 

I'm testing these requests in Postman and eventually building them into a Java application.

2 answers

0 vote

You can't set a null value when you are explicitly calling the field itself to have a value.  By default in Jira, most custom fields that don't have any value will remain with a null or empty value for this field in the database level.  But there is not a way to call that field to have a value and just pass it a null here. 

It looks like you have already explored some other alternatives such as simply not including that field to be defined when the issue is created by removing it from the rest call.

I understand there are some other templates in play here so perhaps that isn't the ideal solution here.

Alternative to that, you might be able to get around this problem by changing the configuration of the custom field in Jira.  Right now your custom field looks something like this in the Jira UI under Issues -> Custom Fields:

customfield1.png

There are a couple of different changes you could make to this field in order get around this.

1: You could set a default value for this field here.  That way you don't have to set a value in your rest call when creating the issue for issues unless the issue needs to have a different value here

2: You could create a new option for this field, and call it something like "unset" or "none".

Or you could do both of these steps.  In which case you could then use the rest call to set the field value to "none".  The difference here though is that this issue would have an actual value for that field when it is created as compared to being a true Null.   It might not make a difference, but it is a subtle change that is worth noting.

I also ran into this situation and found

......
"customfield_20582"
: null,
......

will 'reset' the custom filed to null value.

I am using the jira rest api call.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

168 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you