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

Tedd Terry October 31, 2013

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
Answer accepted
Tedd Terry May 29, 2014
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!

 
Mika Nokka July 28, 2020

Tnx! it really helped when I needed to construct the customfield tag also (the ID number was known) when updating number custom field:

CFIELD=10127
fieldtag="customfield_"+CFIELD
myvalue=12345
mydict = {'{0}'.format(fieldtag): int(myvalue)}
issue.update(fields=mydict)

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2013

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?

Tedd Terry October 31, 2013

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).

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2013

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