1

I'm trying to get elements of custom fields from JIRA.I want to add these elements to windowsform combobox. I can get id and name of custom fileds but I need to get element of dropdonwlist. The customfields are project spesific.

I've been tried code below but it only takes name list of customfileds, but I need to get elements of dropdownlist from jira which is called Activity.

var jira = Jira.CreateRestClient(JiraUrl, txtBoxUsername.Text, txtBoxPassword.Text);   

var issue = jira.Issues.GetIssueAsync(cmBoxCRs.Text);

var customField = jira.Fields.GetCustomFieldsForProjectAsync("BKH").Result;

And I've already tried this:

cmBoxActivity.Text = issue.Result.CustomFields["Activity"].Values[0]

It only returned one value which has been selected on JIRA for spesific issue.

  • By any chance are you using https://bitbucket.org/farmas/atlassian.net-sdk/wiki/Home? Also, ".Values[0]" will return you the first element only, have you tried removing the index (which should return the string[] to you)? – Ian Jun 20 '19 at 05:35
  • cmBoxActivity.Text = issue.Result.CustomFields["Activity"].Values[0] gets only selected value of special customfield but I need all members of this special custom field. I can reach all members from combobox on webpage but I couldn't reach them by using rest api in C#. issue.Result.CustomFields["Activity"].Values returns only one item which is selected one. – Sıla Öztürk Jun 20 '19 at 08:44

1 Answers1

0

This is not possible with the current release of the Atlassian.NET SDK (version 13.0.0). I needed the same functionality and found that Jira does support obtaining the list of allowed values for custom fields as part of the createmeta api request. For example:

rest/api/2/issue/createmeta?expand=projects.issuetypes.fields

(there are params available to limit the responses by projectKeys and issuetypeNames)

I found that the Atlassian.NET SDK is already requesting this data, it just didn't make it available via the API. So I made these values accessible in my fork at https://bitbucket.org/danellisuk/atlassian.net-sdk/src/master/

There is a pull request at https://bitbucket.org/farmas/atlassian.net-sdk/pull-requests/108, so hopefully the functionality will available in the main package soon.

Example use:

Jira jira = Jira.CreateRestClient(url, username, password, settings);

var options = new CustomFieldFetchOptions();
options.ProjectKeys.Add("EXAMPLE_KEY");
options.IssueTypeNames.Add("EXAMPLE_TYPE");

var fields = await jira.Fields.GetCustomFieldsAsync(options);

var field = fields.Where(x => x.Name == "EXAMPLE_FIELD_NAME").First();

foreach (var x in field.AllowedValues)
{
    Console.WriteLine($"ID: {x.Id} Value: {x.Value}");
}
Daniel Ellis
  • 1,225
  • 1
  • 11
  • 6