princenyeche / jiraone

A REST API Implementation to Jira Cloud APIs for creating reports and for performing other Jira queries.
https://jiraone.readthedocs.io
MIT License
25 stars 11 forks source link

How to export issues with needed feilds only? #103

Closed sowndarya2701 closed 1 year ago

sowndarya2701 commented 1 year ago

Hi,

I am trying to use this jiraone module to export issues to CSV using "export_issues" in this module. This gives me export of all fields. How to export only 5 fields which I need?

Thnx.

princenyeche commented 1 year ago

Hey @sowndarya2701

It doesn't support field exclusion yet, you have to do that manually (you can open it up in excel or numbers and remove the columns you do not need) as that's something I will add later to that method. Maybe in a future update once I have the time to work on it.

princenyeche commented 1 year ago

Hey, @sowndarya2701 just want to update you on this, with the new version v0.7.6 you can do field inclusion to export only the fields that you have. You have to supply a list of the fields that you want in the export. These fields must use the exact string name as shown on your Jira UI.

# previous express
include = ["Summary", "Environment", "Labels", "Assignee", "Reporter"]
issue_export(jql=jql, include_fields=include)

Subsequently, you can export only current fields as well, which is the same as how it shows you on your advanced issue search on the UI.

# previous express
issue_export(jql=jql, field_type="current")
synergiator commented 1 year ago

Hi! Testing field export with v. 0.7.7

issue_export(jql=jql, final_file="output/jira_dump.csv", field_type="current")

Error: jiraone.jira_logs:jira_logs.py:54 The following name(s) "Sprint,Watchers,Reporter,Assignee" in the field value list doesn't seem to exist or cannot be found.
 jiraone.exceptions.JiraOneErrors: <JiraOneError: Unable to find initial field, probably such field "Sprint,Watchers,Reporter,Assignee" doesn't exist for fields argument>

issue_export(jql=jql, final_file="output/jira_dump.csv", fields=fields)

Error: jiraone.exceptions.JiraOneErrors: <JiraOneError: Unable to find initial field, probably such field "id,description,name,key" doesn't exist for fields argument>

While my custom fields list looks like ["id","description","name", "key"], I assume, the program logic merges the array somewhere to a concatenated string?

princenyeche commented 1 year ago

Hi @synergiator

Those are common fields which should exist on Jira based on the first error. However, it seems that they don't exist in your instance. For the second error, the field names have to be an exact string of the custom or system field name. i.e. description -> Description, key -> Key as those are the names of the system field. If you're trying to get the Id of an issue, I believe this is typically associated with the key rather than it be a separate name, so capitalizing them if the script can't find the name from the fields endpoint, will return that error.

So, if you want to export only current fields and you're getting such errors then you can do this

# previous statements
check_fields = []
issue_export(jql=jql, final_file="output/jira_dump.csv", field_type="current", fields=check_fields)

The fields arguments won't check for anything since it's empty.

synergiator commented 1 year ago

thanks a lot for quick response and working fix! the trick has worked for me! :) Side note: it seems that the program logic creates a local folder "EXPORT" and assumes subdirectories if named in output path. Getting error like this:

target = "output/jira_dump_tasks.csv"
issue_export(jql=jql, final_file=target, fields=fields)

FileNotFoundError: [Errno 2] No such file or directory: '<ABSPATH>/<PROJECTFOLDERNAME>/EXPORT/output/jira_dump_tasks.csv'

The workaround was here to create a folder named "output" under "EXPORT".

synergiator commented 1 year ago

Btw, wrt to field filtering: from the dump, I picked just two fields, "Status" and "Assignee" assuming while they seem to exist, I could test the export just with them.

fields = ["Status", "Assignee"]

However, there is still that error "The following name(s) "Status,Assignee" in the field value list doesn't seem to exist or cannot be found."

princenyeche commented 1 year ago

About that, the final_file argument expects a file name which should be a string. It doesn't prepend a directory if it doesn't exist. So I suggest if you want to use a directory, the folder argument would be the best choice here. You can name any directory within and it will create it and link it to the file.

When it comes to filtering, the fields argument doesn't perform filtering, it does a lookup of field value to rewrite when this argument target is used. If you want to filter fields, then you should use the include_fields or exclude_fields argument. The latter as the name implies excludes fields based on the field name, the way they exist on Jira fields. However, the exclude_fields are only good when you want a whole lot of fields but require certain ones excluded. The former is the one you should rely on when it comes to field filtering as it will only include fields you mention, given that they exist on Jira fields.

Another point to note here is that the field name and the way they are exported don't necessarily mean that all will exist as the same name. You can confirm this from your Jira environment by visiting your <instances.jira.com/rest/api/latest/field> as that is a clear indication of what the actual name would be. Although, it's strange how in your environment, you can't find those fields as they are very common. Could you try this prior to running the script?

# previous express
LOGIN.api = False
fields = ["Status", "Assignee"]
issue_export(jql=jql, folder="output", final_file="jira_dump.csv", include_fields=fields)
sowndarya2701 commented 11 months ago

Hi,

I get below error even though those fields exists in my Jira instance.

JiraOneError: Unable to find initial field, probably such field "Sprint,Watchers,Reporter,Assignee" doesn't exist for fields argument>

Do you know why ?

Other observations :

Can you please help to solve ?

Thanks, E.Sowndarya.

On Sat, May 27, 2023 at 5:34 PM Prince @.***> wrote:

Hey, @sowndarya2701 https://github.com/sowndarya2701 just want to update you on this, with the new version v0.7.6 you can do field inclusion to export only the fields that you have. You have to supply a list of the fields that you want in the export. These fields must use the exact string name as shown on your Jira UI.

previous expressinclude = ["Summary", "Environment", "Labels", "Assignee", "Reporter"]issue_export(jql=jql, include_fields=include)

Subsequently, you can export only current fields as well, which is the same as how it shows you on your advanced issue search on the UI.

previous expressissue_export(jql=jql, field_type="current")

— Reply to this email directly, view it on GitHub https://github.com/princenyeche/jiraone/issues/103#issuecomment-1565373230, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQPWSA2QB2BHD55R3E4DQWDXIHUULANCNFSM6AAAAAAS6VK3AA . You are receiving this because you were mentioned.Message ID: @.***>