Forums

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

Get organization of issue via API

Michel
Contributor
September 11, 2018

Hi,

 

I'm using an Python script to get worklog entries for our monthly billing of issues in Jira Service desk. 

However, I'm unable to fetch the organization. It seems that the field organization(s) is unavailable

# Init
jira = JIRA(basic_auth=(settings.jirauser, settings.jirapw), options={'server': settings.jiraurl})

# JQL
jirajql = "updated >= startOfMonth(-10) AND updated <= endOfMonth(-0)"

# Fetch items
issues_in_project = jira.search_issues(jirajql, maxResults=False,
fields="reporter,issuetype,summary,worklog,status,created,updated,resolved,components,priority,resolution")


# Loop trough the issues
for value in issues_in_project:

log_entry_count = len(value.fields.worklog.worklogs)

# Loop trough the worklogs
for i in range(log_entry_count):
print "ID: " + str(value.key)
print "Reporter: " + str(value.fields.reporter.displayName)
print "E-mail: " + str(value.fields.reporter.emailAddress)
print "Organization: " + str("Organization here")
print "Summary: " + str(value.fields.summary)
print "Author: " + str(value.fields.worklog.worklogs[i].author)
if hasattr(value.fields.worklog.worklogs[i], 'comment'):
print "Comment: " + str(value.fields.worklog.worklogs[i].comment)
print "Started: " + str(
(dateutil.parser.parse(value.fields.worklog.worklogs[i].started).strftime('%d/%m/%Y %H:%M')))
endtime = dateutil.parser.parse(value.fields.worklog.worklogs[i].started) + timedelta(minutes=value.fields.worklog.worklogs[i].timeSpentSeconds / 60)
print "Ended: " + str(
(endtime.strftime('%d/%m/%Y %H:%M')))
print "Minutes: " + str(value.fields.worklog.worklogs[i].timeSpentSeconds / 60)
print "-------------------------------------------------------------------------------------------------------------------------------"

 

Any idea's? A workaround could be that I use "GET /rest/servicedeskapi/organization/{organizationId}/user" to loop trough all organizations, and see if there is a match with the specific user, but that seems rather inefficient.

 

Thanks

 

1 answer

0 votes
Mohamed Benziane
Community Champion
September 11, 2018

Hello @Michel

I'm not an expert in python but in your <fields=">, can you try to add organizations

and instead of 

str("Organization here")

try

 

value.fields.customfield_11400

Change '11400' by the id assigned to your organizations fields

 

Regards

Michel
Contributor
September 11, 2018

Hi,

organization is a standard field in Jira Service Desk. So I would suppose it has a named reference. However, value.fields.organization or value.fields.organizations does not work.

Like Alexandr Zabortcev likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events