Forums

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

How can I append multiple fixversions using python jira rest api ?

Arjun Eswaran February 11, 2021
issue.update(fields={'fixVersions':[{'name':current_fixVs[0]},{'name':current_fixVs[1]},{'name':current_fixVs[2]},{'name':current_fixVs[3]}]})

considering 4 fix versions the above code works without overwriting(acutally overwrites) existing because I fetch the existing fixversion and append(otherwise it overwrites) to the array.

But I cannot keep updating the code by adding another element from the array - current_fixVs[4] as the number of fix versions will dynamically change. Also, the api won't accept a single array(containing all fixversions) to be added as fixversion.

2 answers

0 votes
Prince Nyeche
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 Leaders.
February 13, 2021

Hi @Arjun Eswaran 

Welcome to community! Those type of fields are a bit tricky to work with. However I have a script called jiraone that could help with updating the field options on various issues while maintaining the previous values. It has a field variable you can use to call defined methods used for updating Jira fields. You can try it for your server instance by looking at the method.

You can install via pypi by using.

pip install jiraone

For more details on the parameters, you can refer to the documentation here. Hope this can help you with your use case.

Arjun Eswaran February 16, 2021

Thank you.

Do I need to rewrite entire script?

Prince Nyeche
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 Leaders.
February 16, 2021

No, you just need to simply make a call to the method field.update_field_data() 

Example usage:

from jiraone import field, LOGIN

user = "username"
password = "password"
link = "https://<serverinstance>.com"
LOGIN(user=user, password=password, url=link)

issue = "T6-75"  # issue key
fields = "Fix versions" # a fix version system field
case_value = ["COM Row 1", "Thanos"] for value in case_value: c = field.update_field_data(data=value, find_field=fields, key_or_id=issue,
options="add", show=False, field_type="system") print(c)

I haven't tested it properly on servers but Jira is basically the same software and the payload should be the same. You can add a list and loop over it as shown above or if you intend to add or remove just one item, then add it as a string.

Arjun Eswaran February 17, 2021

Sorry, that I didn't use jiraone as I found the solution myself.

 

Arjun Eswaran February 17, 2021
if 'Fixed' in issue.fields.status.name and issue.fields.fixVersions is None:
issue.update(fields={'fixVersions':fixV})
jira.transition_issue(issue, transition='Integrate fix')
rep = my_issues.fields.reporter.name
elif 'Verified' in issue.fields.status.name and issue.fields.fixVersions is not None:
for fvs in issue.fields.fixVersions:
all_fixvs.append({'name':fvs.name})
all_fixvs.append({'name':fixV})
try:
issue.update(fields={'fixVersions':all_fixvs})
except IndexError:
pass
Like Prince Nyeche likes this
0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
February 12, 2021

Hi @Arjun Eswaran I'm not Python developer, but can you try to share bigger part of the code?

Arjun Eswaran February 14, 2021
def update_fixversion(issue, fixV):
print(issue)
rel = issue.fields.customfield_10390
rep = issue.fields.reporter.name
for item in rel:
variant = item.value
if 'Fixed' in issue.fields.status.name and issue.fields.fixVersions is None:
issue.update(fields={'fixVersions':fixV})
jira.transition_issue(issue, transition='Integrate fix')
elif 'Verified' in issue.fields.status.name and issue.fields.fixVersions is not None:
for fvs in issue.fields.fixVersions:
current_fixVs.append(fvs)
current_fixVs.append(fixV)
try:
issue.update(fields={'fixVersions':[{'name':current_fixVs[0]},{'name':current_fixVs[1]},{'name':current_fixVs[2]},{'name':current_fixVs[3]}]})
except IndexError:
pass

Suggest an answer

Log in or Sign up to answer