Get parent id from jira using python

Himanshu_Pant April 4, 2018

Hi Guys,

Could you please help to get parent id

import jira.client
from jira.client import JIRA

options = {'server': 'https://example.com', 'verify':False}
jira = JIRA(options, basic_auth=('user', 'password'))
issues_in_project = jira.search_issues('project=11372 AND SPRINT not in closedSprints() AND sprint not in futureSprints()')
for value in issues_in_project:
print value.key , value.id, value.fields.summary , value.fields.assignee , value.fields.reporter ,value.fields.updated ,value.fields.resolutiondate, value.fields.duedate, value.fields.labels

 

 

Here,  value.fields.id is showing child Id, I want the parent id as well. 

For example- When we export jira details from jira by selecting all fields in CSV format..By automatically we get issue Id and corresponding parent id

I want to understand how it getting parent id from child (value.fields.id)

 

Is there any field through I can get directly.parent id ? Like any customfield or value.fields.parent something

 

Please have a look once and It will be very great if anyone can help on this

 

 

Thanks

 

2 answers

1 accepted

1 vote
Answer accepted
Shaun S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 5, 2018

Hi Himanshu,

 

I was scratching my head with this one for quite awhile, but I think I've figured out the issue here.  Your query:

'project=11372 AND SPRINT not in closedSprints() AND sprint not in futureSprints()'

I suspect there are issues returned in those results that are not subtasks.  Since those issues wouldn't have a parent ID, the print function fails.  By adding try/except logic to the code, I was able to retrieve the parent ID for the subtasks included in the query.

Change your for loop to the following and see if that does the trick.

for value in issues_in_project:
try:
print value.key , value.id, value.fields.summary , value.fields.assignee , value.fields.reporter ,value.fields.updated ,value.fields.resolutiondate, value.fields.duedate, value.fields.labels, value.fields.parent.id
except:
print value.key , value.id, value.fields.summary , value.fields.assignee , value.fields.reporter ,value.fields.updated ,value.fields.resolutiondate, value.fields.duedate, value.fields.labels
0 votes
Jay Wang July 21, 2022
issue = jira.issue('DMT-893')

print(issue.fields.parent.key)
Jay Wang July 21, 2022
'parentIssue':     str(issue.fields.parent.key) if issue.fields.issuetype.subtask == True else ''
To avoid Epic parent but keep parent issue key (parent task)

Suggest an answer

Log in or Sign up to answer