Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

Hi! 

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

@sohny_pulikien 

Did you get it resolved?

Thanks

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

 

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

@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

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"}]}

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

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 

@sohny_pulikien 

I am new to this jira-python.

Can you please help me the code.

Thanks

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you