Why can't our python script update a custom field?

We use a python script to transition issues through some interaction with our build system. The workflow is like this: an issue is sent to an Enqueued status, the build machine queries a building project for its Enqueued issues, transitions them to a reserved status while they build, and then transitions them toward QA once they're built.

Our python script manages manages these transitions and also adds a comment with the appropriate build number.

It would be more useful for us if we updated a custom field with the fix build number. However, we ran into an issue implementing this in our python script: it appears as though the custom field can't be accessed or updated.

We were trying to update our custom field using these instructions:

This is the line we tried on our test issue:
issue.update(fields={'customfield_11900': arg.buildnumber})


This is the error we're getting:
File "BuildToVerifyJira.py", line 47, in <module>
issue.update(fields={'customfield_11900': 123})
File "c:\python27\lib\site-packages\jira\resources.py", line 194, in update
super(Issue, self).update(**data)
File "c:\python27\lib\site-packages\jira\resources.py", line 73, in update
raise_on_error(r)
File "c:\python27\lib\site-packages\jira\exceptions.py", line 42, in raise_on_error
raise JIRAError(r.status_code, error, r.url)
jira.exceptions.JIRAError: HTTP 400: "{u'customfield_11900': u"Field 'customfield_11900' cannot be set. It is not on the appropriate screen, or unknown."}"
Opening the API view of the bug (ie https://*******.<a< a="">href="http://atlassian.net/rest/api/2/issues/24277"> atlassian.net/rest/api/2/issues/24277) shows customfield_11900 set to the value seen when using the web view.
We have tried adding the custom field to a screen at every possible place in the workflow, but ran into the same issue.
We have triple-cheked the customfield ID (it was obtained from a JQL query for the field name).
We also tried variations on the arg.buildnumber like:
fields={'customfield_11900': 123})
fields={'customfield_11900': '123'})
fields={'customfield_11900': ['123']})
We are using jira-python:
Any help would be tremendously apprecaited! Thank you!

2 answers

1 accepted

0 votes
Accepted answer
Eventually, this worked: 
issue.update(fields={'customfield_11900': int(args.buildnumber)})

Syntax for args may have been a problem, and we also found that we needed to cast the argument string as an int.

Hope this helps someone with a similar issue!

 
0 votes

What type of field is it? I knwo you've said you've got the field on-screen in every point in the workflow, but could you also check the "edit" screen for the issue type?

Number field, Global to all issue types, and I did have it on our default screen when we were looking at this. For reference, I used the same configuration as a Label field which is successfully retrieved (but not updated) by the same script.

The Edit Screen is declared in the Screen Scheme, right? That appears to be correctly configured for what we're doing (the field is present on screens associated with the issue type).

Ok, my worry was that it might be a read-only field, or one that disallows edits for some reason. Plus, if it's not on the "Edit" screen, then REST might not have been able to get to it as it respects the ui settings.

I'm afraid I'm stuck, as your code looks like it really should be working.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,911 views 19 22
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