dapplo / Dapplo.Jira

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

CustomFields are not working #43

Closed DerKiLLa closed 4 years ago

DerKiLLa commented 4 years ago

Hi! I tried your code, but issue.Fields.CustomFields.Count returns 0 in every issue.

But the issue does have a lot of customfields. Any help?

Example:

? issue
{Dapplo.Jira.Entities.Issue}
    Changelog: null
    Fields: {Dapplo.Jira.Entities.IssueFields}
    Id: "20265"
    Key: "CRM-2976"
    RenderedFields: null
    Self: {http://jira.engrotec.lokal/rest/api/2/issue/20265}
? issue.Fields.CustomFields.Count
0

But when i open the issue in my browser (http://jira.domain.local/rest/api/2/issue/20265/), i get:

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"20265","self":"http://jira.engrotec.lokal/rest/api/2/issue/20265","key":"CRM-2976","fields":{"customfield_12011":"test@test.com","customfield_13100":null,"customfield_12010":null,"customfield_12013":"www.test.com","customfield_12015":null,"resolution":null,"customfield_12017":null,"customfield_10510":null}}

Thanks in advance!!!

Lakritzator commented 4 years ago

Maybe you can write how you use my code? You need to know that if you search for issues, only a "digest" (subset of the information) is retrieved. You should use the Issue.GetAsync call to retrieve all the data, or it's possible to force the search to return more but this is not adviced.

I have a test-case for the custom fields, so it's unlikely that it returns 0 fields. https://github.com/dapplo/Dapplo.Jira/blob/master/src/Dapplo.Jira.Tests/IssueTests.cs#L99

If that solves your issue, I really must update my documentation...

DerKiLLa commented 4 years ago

Indeed we are using SearchAsync...

            var jiraClient = JiraClient.Create(new Uri("http://jira.domain.local/"));
            jiraClient.SetBasicAuthentication("user", "pass");
            var searchResult = await jiraClient.Issue.SearchAsync(Where.Text.Contains("test"));
            foreach (var issue in searchResult.Issues)
            {
                if (issue.Fields.CustomFields.Count > 0)
                    Debug.WriteLine(issue.Fields.Description);
            }

How can we get all Issues using GetAsync? Otherwise i can just use this inside the loop:

var searchIssue = await jiraClient.Issue.GetAsync(issue.Key);
if (searchResult2.Fields.CustomFields.Count > 0)
Debug.WriteLine(searchResult2.Fields.Description);
Lakritzator commented 4 years ago

Just to be clear, this what we talk about is the way Atlassian build it's API. Not all fields are returned when doing a search, unless you specify what you want to become.

The "easiest" is to get the relevant details inside the loop, but if you really have MANY JIRA issues you will cause a lot of traffic.

You can also specify for the search which (custom) fields you like to have but you will need to know their id beforehand!! I've specified this in the documentation, which for the search is here See the fields argument!

The fields selected by default are in the configuration, as described here and there is a link to the source so you can see what values this has.

You will need to call the search with those values complemented with e.g. "customfield_12013".

DerKiLLa commented 4 years ago

Wow, thank you very much! I've changed my code and it works!

IEnumerable<string> customFields = new List<string>() { "customfield_12000", "customfield_12001" };
var searchResult = await jiraClient.Issue.SearchAsync(Where.Watcher.Is("user"), -1, 0, customFields, null, default(CancellationToken));

How can i use 2 IFinalClause? I need

Where.Watcher.Is("user")
Where.Project.Is("CRM")

Do u also support issuetype?

And can i login via BasicAuthEncoded without username?

Lakritzator commented 4 years ago

You might still want to supply the fields which are in JiraConfig.SearchFields, maybe you can concat them to the fields you specified.

You mean how to query with 2 values? There is a bit of documentation, it's not pretty, which might help: https://www.dapplo.net/Dapplo.Jira/articles/queries.html

To make a long story short, you probably are looking for this: Where.And(Where.Watcher.Is("user"),Where.Project.Is("CRM"))

DerKiLLa commented 4 years ago

Thanks for your help! Works like a charm :)

IssueType can be filtered via Where.Type.Is("number")