Not able to add value to custom field list in python jira

sohny.pulikien November 26, 2019

I have custom field which takes a list of users , I am not able to update it with new values using jira python script. Please find below the method i have used 

 

-> testuser = jira.user('rtracy')

(Pdb)

> /u/cm/sandbox/createG2jira_test.py(50)create_G2()

-> G2_issue.fields.customfield_14904.append(testuser)

(Pdb) testlist = G2_issue.fields.customfield_14904

(Pdb) p testlist

[<JIRA User: displayName='Jai Dembla', key='jdembla', name='jdembla'>, <JIRA User: displayName='Ramesh Babu Nidadavolu', key='rbabu', name='rbabu'>, <JIRA User: displayName='Rick Stoneking', key='rstoneking', name='rstoneking'>, <JIRA User: displayName='Vakil Arora', key='varora1', name='varora1'>]

(Pdb) testlist.append(testuser)

(Pdb) p testlist

[<JIRA User: displayName='Jai Dembla', key='jdembla', name='jdembla'>, <JIRA User: displayName='Ramesh Babu Nidadavolu', key='rbabu', name='rbabu'>, <JIRA User: displayName='Rick Stoneking', key='rstoneking', name='rstoneking'>, <JIRA User: displayName='Vakil Arora', key='varora1', name='varora1'>, <JIRA User: displayName='Robert Tracy', key='rtracy', name='rtracy'>]

(Pdb) G2_issue.update(fields={'customfield_14904': testlist } )

*** TypeError: Object of type 'User' is not JSON serializable

I am not sure what I am doing wrong

2 answers

1 accepted

0 votes
Answer accepted
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 11, 2021

Hi! 

the method expect to have a list of usernames instead the list of User Objects

0 votes
Teja May 12, 2021

@sohny.pulikien 

Did you get it resolved?

Thanks

sohny.pulikien May 12, 2021

Yes I was able to resolve it as mentioned above by Gonchik. code snippet below:

 

issue.update( {"customfield_14904":[{"name" : "spolakoen"},{"name" : "rtrimbed"}]})

Teja May 12, 2021

@sohny.pulikien 

I was trying to append user to the list without disrupting existing users in the list.

Same like your code

for issue in jira.search_issues('project = "xyz" and issuetype = Epic and status not in (Closed) and Testers in (rkapoor)', maxResults=100):

print('{}: {}'.format(issue.key, issue.fields.customfield_10600))

testuser = jira.user('rkapoor1')

testlist = issue.fields.customfield_10600

testlist.append(testuser)

testlist1 = ','.join([str(i) for i in testlist])

print(testlist1) //to check in console

issue.update(fields={"customfield_10600": testlist1})

It does not work at all.

Thanks

sohny.pulikien May 12, 2021

You are again doing the same mistake which i did, ur taking an object of username... i suggest u directly pass the name string . 

Ex:  the line 

testuser = jira.user('rkapoor1')

is the culprit. this will give u an object which is not useful.  instead pass the name string rkapoor to name feild as is 

issue.update(fields={"customfield_10600": [{"name" : "rkapoor1"}]}
Teja May 12, 2021

Actually, this code replaces all the user with "rkapoor1".

issue.update(fields={"customfield_10600": [{"name" : "rkapoor1"}]}

Just wanted to append "rkapoor1", when JQL finds "rkapoor" in the Testers field (the Testers field might contain other users as well 

SS:

tester1.PNG

sohny.pulikien May 12, 2021

Ah that makes it easier, read the values from the field, assign it to a variable and then assign it back including new values appended in the list 

Teja May 12, 2021

@sohny.pulikien 

I am new to this jira-python.

Can you please help me the code.

Thanks

sohny.pulikien May 21, 2021

I would suggest u can google on how to assign values to list in python and from there use the above functions that's mentioned above

Suggest an answer

Log in or Sign up to answer