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.
Community moderators have prevented the ability to post new answers.
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.
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; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.