The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Gonchik Tsymzhitov
Community Champion
February 11, 2021

Hi! 

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

0 votes
Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
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

TAGS
AUG Leaders

Atlassian Community Events