I am building a plugin that creates subtasks of one or more given tasks. I want to copy only those fields that are mandatory from parent task to subtask. How to check which fields are required?
First, you first can get fall field candidates using the Interface FieldManager. The call is
fields=fieldManager.getOrderableFields()
Then you iterate through this collection and for each Field you can call this method to decide if the field is required
public static boolean isFieldRequiredForSubIssueTypeAndProject (Long subIssueTypeId, GenericValue projectGV, Field field) throws FieldLayoutStorageException { final FieldLayoutManager fieldLayoutManager = ComponentManager.getInstance().getFieldLayoutManager(); FieldLayout layout = fieldLayoutManager.getFieldLayout(projectGV, subIssueTypeId); if (layout == null || layout.getId() == null) { layout = fieldLayoutManager.getEditableDefaultFieldLayout(); } FieldLayoutItem flo = layout.getFieldLayoutItem(field.getId()); if (flo == null) return false; return flo.isRequired(); }
subIssueTypeId is the id of your subtask issue type, projectGV is the GenericValue of your project. projectGV could be retrieved from the parent issue using this snippet:
issue.getProjectObject().getGenericValue()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.