Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How i can get values of the Fields using Jira API

satya L June 26, 2012

Hi,

I want to get all the default values populated for the FIELD using JIRA API.

For Ex : FixVersion is a select field which may populates some default values in its "Select" dropdown llist. I want to retrive all those values populated in that dropdown list.

I want to know how to find out those "Fields" which populates predefined values and values of those Feilds using Jira API.

Can any one please suggest solution or share some sample code for this.

Thanks in Advance,

Satya.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Alex Taylor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012
Collection<Version> versions = versionManager.getVersions(project.getId());

Collection<Version> versions = versionManager.getAllVersions();

Collection<Priority> priorities = constantsManager.getPriorityObjects();

And so on :-)

satya L June 26, 2012

Thnkx Alex and Mizan ..

Let me try with this stuff ..

satya L July 22, 2012

Hi Mizan,

def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()
  
def cf = customFieldManager.getCustomFieldObjectByName("SelectListA")
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find {it.value == "BBB"}

In the above code, what Does it mean if "fieldConfig" returns me NULL.

Regards,

Satya

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

If you want all the options in a customfield then see this Api.

satya L June 26, 2012

Thnx for your response Mizan..

Sample code please? If there is any ..

Regards,

satya.

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

What are you trying to do ? can you explain the scenario ? why you need the options of a field ?

Do you need the options or the default value selected in the field when you create aissue

satya L June 26, 2012

Actually I want to create Issues in Jira by using Jira API , for this i get all the required information like projectName and all the field names issueTpe, Summary, Priority, Fixversion .. etc.. and its values as my Input data/Source data.

So before creating the issue I need to validate my source data whether it has Desired Field values to create the Issue or not.

For Ex: Let us assume that i have a select filed called "Country" and it has predefined values as 'India', 'USA', 'UK' populated in its Dropdown list.

Here I need to ensure that My source data should only contain any one of the above mentioned values (ie., 'India', 'USA', 'UK') for the Filed "Country".

Regards,

Satya.

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

Have this groovy code , had found it on answers . you will have to convert it to Java because the .find is not available in Java . You will have to iterate through the options and check if the value is present or not

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
 
def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()
 
def cf = customFieldManager.getCustomFieldObjectByName("SelectListA")
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find {it.value == "BBB"}
issue.setCustomFieldValue(cf, option)

satya L June 26, 2012

Okay .. Thnx ..

Any samples for System fields ..?

satya L July 22, 2012

Hi Mizan,

def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()
  
def cf = customFieldManager.getCustomFieldObjectByName("SelectListA")
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find {it.value == "BBB"}

In the above code, what Does it mean if "fieldConfig" returns me NULL.

Regards,

Satya

0 votes
Alex Taylor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

AFAIK there is nothing that will give you a list of all fields which have predefined values. You need to know which field(s) you are interested in.

satya L June 26, 2012

Oh.. Okay .. But How i can get the predefined values of a particular field then ..?

Alex Taylor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

As I said: it depends on the field. The values aren't necessarily tied to the field - to use your example of earlier, the values displayed in the FixVersions field are nothing to do with the field itself; they come from the VersionManager.

Most of the other built-in fields - IssueType, Priority, Status, Resolution, etc - get their values from the ConstantsManager. For a custom field you need to get the CustomField object and call its getOptions() method.

satya L June 26, 2012

Okay .. Thnx Alex ..


But asking with Curiosity .. Is there any other way /API-method which takes my Project and Field names as input and gives me the values of that particular field ..

Regards,

Satya.

Alex Taylor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

No. Fields are not tied to Projects - their predefined values are global.

satya L June 26, 2012

okay.. Thnx Alex ..

0 votes
Alex Taylor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012
satya L June 26, 2012

Thnx Alex for your response..

But what my requirement here is to get all the defult populated values of the FIELDs.

For Ex : FixVersion is a select field which may populates some default values in its "Select" dropdown llist. I want to retrive all those values populated in that dropdown list.

Thanks & Regards,

Satya.

Alex Taylor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 26, 2012

Ah, sorry, I misunderstood your question.

It depends on the field - for FixVersions you need to look up the list of Versions for either a specific project or the entire system. VersionManager.getAllVersions() or VersionManager.getVersions(projectId) will do this for you:

http://docs.atlassian.com/software/jira/docs/api/4.4.4/com/atlassian/jira/project/version/VersionManager.html

There are similar APIs for IssueType, Component, Status and so on.

satya L June 26, 2012

It's Ok Alex..Thanks once again ..

I just mentioned the "FIxVersion" as an example for those kind of filelds, like that in JIRA we have so many filelds which poplulated predefined values populated .

So i want to get all the values of those kind of Fields.

So here i know the Project Name, and IssueType's associlated with this project and Fields associated with each of these IssyeTypes.

Now out of above list of Fields I want to get the Field names which populates predefined values and then need to find out the values of those Feilds .

Regards,

Satya.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events