dapplo / Dapplo.Jira

This is a simple REST based JIRA client, written for Greenshot, by using Dapplo.HttpExtension
MIT License
35 stars 14 forks source link

What is the key for a custom field on issues? #13

Closed casperOne closed 7 years ago

casperOne commented 7 years ago

When setting a custom field on an issue, what do we use for the key?

Do we use customfield_[0-9]+ ID value as the key, or should we use the name as the key?

Or something else?

Lakritzator commented 7 years ago

Yes, custom fields are not something I can build into the library, as I don't know what customizations are used, so you will need to use something like issue.Fields.CustomFields["customfield_10001"]. Also, the type returned is depending on the content!

Dapplo.Jira was mainly written to overcome the mapping and handling of most of the communication, and I am just starting to make things more comfortable.

Recent versions make it possible to find the ID for fields by a name:

var fields = await jiraClient.Server.GetFieldsAsync()
// Write something to find your custom field in the result (hint, there is a bool IsCustom or something)

This way you can write code which at least is not depending on your environment, sometimes people have test and production systems where the ID's are not the same.

I am considering some method overloads, those where issues are returned, where you can specify your extended class. This actually already works for the agile domain.

casperOne commented 7 years ago

I believe that I've gotten this, I'll close once I'm able to save when #11 is resolved as it revolves around custom fields not being serialized and sent to the server.

casperOne commented 7 years ago

The custom fields are going through on the creating of issues, thank you!

andersand commented 4 years ago

The API is very good but the docs not so much. There's not even mentioned in the tests how to create issues with custom fields. After reading this I found out that you need to specify customfield_ prefix to the customfield Id.

For anyone else stumbling upon this post, this works in Jira 8.9

            var issueToCreate = new Issue
            {
                Fields = new IssueFields
                {
                    Project = new Project {Key = project.Key},
                    IssueType = issueType,
                    Summary = summary,
                    CustomFields =
                    {
                        { "customfield_10919", myCustomFieldValue1},  // for a Jira string field
                        { "customfield_11223", new string[] {"label1 label2 label3"}}, // for a Jira label field
                    }
                }

            };
Lakritzator commented 4 years ago

@andersand thanks for the hint, this will help others.

Just to be clear, this project is something I made in my free time, mainly just one person. There is much room for improvements, and I gladly merge any contributions, especially documentation.

I might be a good idea to write some additional articles for the documentation here: https://www.dapplo.net/Dapplo.Jira/index.html If you like to help, it would be nice if you could create a "creating issues" article using markdown in the doc/articles directory and create a pull-request for it.

Lakritzator commented 4 years ago

@andersand I also would love to see a discussion about the API, I guess we can create an issue builder or something. But as I mainly needed JIRA access for reading, I didn't have any reason to think much about it.

andersand commented 4 years ago

@Lakritzator for now I've forked your repo and added a test that shows how. I've also added a new feature to the library, enabling users to create issue links with Dapplo.Jira - I will make a pull request