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.

1 answer

0 votes

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.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot