How to get a custom field values from parameters in JIRA

I created new Custom Field and in the implementation of any methods

validateFromParams() or getSingularObjectFromString()

I would like to get the values of the other custom fields,

but the values which are just typed in the forms and not taken directly from the database

like example below:

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();

Issue issue = issueManager.getIssueObject("JIRA-123");

So I have a list of all the custom fields:

List<CustomField> customFields = customFieldManager.getCustomFieldObjects();
for (CustomField element : customFields) {
	System.out.println(
		element.getFieldName() + "\n" + element.getId() + "\n"
		+ "VALUE: " + element.getGenericValue() + "\n" 
		+ "============================="
	);
}

but I cannot see the method for getting value (getGenericValue() doesn't return it).

Do you know any solutions for it?

Michal

4 answers

1 accepted

Hi, 

You have to pass other customfield's value as a part of your custom customfield value. How you can do that?

Use javascript to put other cf value in hidden text input with name:

name="customFieldId.id:1"

then in your CF in method getValueFromCustomFieldParams you can extract this value like here:

relevantParams.getValuesForKey(1)

Hope it was helpful.

Cheers,

0 vote
Tuncay Senturk Community Champion Aug 11, 2014

Hi,

As far as I understand your question, you need to

issue.getCustomFieldValue(element)

Tuncay

Thanks Tuncay,

I already tried it, but the value is taken from the database directly, but I need value from the just edited form. Moreover when you click "Create Issue" button, enter some values and press Save, you don't have Issue ID yet in the validateFromParams() method.

I goal is to make field "B" required only when field "A" is not empty. I don't want to do this using JS, because I want this validation for the following: edit, quick edit, inline edit, bulk change, REST API and also for the all transitions. The condition can be hardcoded in the Java code, I am okay with it.

Michal

0 vote
Tuncay Senturk Community Champion Aug 11, 2014

Hmm, I see the problem, sorry for my prior answer.

Since the value is not persisted, it lives on client side and I do not think there may be any solution without javascript. I can suggest workflow validators but as you mentioned you can only use it on transitions, not in edit, inline edit or such modes.

Sorry, but I have no idea :(

Tuncay

Hi Krzysztof,

This is exactly what I was looking for. I guess, when we edit issue via REST, we cannot get other field values to validate dependent fields. Am I right?

Michal

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jun 14, 2018 in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

526 views 3 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you