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

List Required Fields

Radek Kantor
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.
November 15, 2011

How can I programmable list all required fields visible on create issue screen?

I try:

final Set<NavigableField> fields = fieldAccessor.getAllAvailableNavigableFields();

and than filter for required as

FieldLayoutItem fieldLayoutItem = getFieldLayoutItem(issue, field);  

if (fieldLayoutItem != null) return fieldLayoutItem.isRequired();

where fieldLayoutItem is result of:

if (issue.getIssueTypeObject() != null) {

// Null for create sub-task if issue type rule is not apply yet

	layout = fieldLayoutManager.getFieldLayout(

	issue.getProjectObject().getGenericValue(), issue.getIssueTypeObject().getId());

}

if (layout == null || layout.getId() == null) {

layout = fieldLayoutManager.getEditableDefaultFieldLayout();

}

return layout.getFieldLayoutItem(field.getId());

But this code list all required fields, not only visible on specific screen.

Thanks for help.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Wojciech Seliga
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.
November 15, 2011

Hi,

Have you taken a look at com.atlassian.jira.web.action.issue.CreateIssue - webwork class (and its descendants actually) responsible for rendering issue (or sub-task) creation screen?

Namely, you will need FieldScreenRenderer, which you can create via IssueCreationHelperBean or FieldScreenRendererFactory.getFieldScreenRenderer() directly (passing there IssueOperations.CREATE_ISSUE_OPERATION).

The trick is that you are about to create an issue, but to get FieldScreenRenderer you have to pass ... Issue object.
In fact it could be a "dummy" issue object. Just make sure it has two properties: project and issue type.

So the code like:

Issue issue = issueFactory.getIssue();
issue.setProject(yourProjectGv);
issue.setIssueType(yourIssueType)

should give you a minimal working issue which you can pass to retrieve FieldScreenRender.

From here you can easily get your FieldScreenRenderLayoutItem (you probably won't bother about screen tabs) and OrderableField objects.

Radek Kantor
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.
November 16, 2011

Thanks for posting correct solution.

public static List<Field> getIssueRequiredCreateFields(User user, Issue issue) {
		List<Field> requiredCreateFields = new ArrayList<Field>();
		FieldScreenRenderer fsr = ComponentAccessor.getFieldScreenRendererFactory().getFieldScreenRenderer(user, issue, IssueOperations.CREATE_ISSUE_OPERATION, false);
		for (FieldScreenRenderLayoutItem fsrla : fsr.getRequiredFieldScreenRenderItems()) {
			requiredCreateFields.add(fsrla.getFieldScreenLayoutItem().getOrderableField());
		}
		return requiredCreateFields;
	}

Yagnesh Bhat
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 29, 2015

the Issue class ddoesnt have a setter method anymore in 6.4 jira. Any workarounds would really help. I am also trying to do exactly the same thing but for JIRA 6.4. Please help

TAGS
AUG Leaders

Atlassian Community Events