I would like set some fields as required in a field configuration by groovy script. Someone have any sample code to do it?
I didn't have any sample code, but a quick search through the JavaDoc and I think you'll want to use the FieldLayoutManager to find the Field Layout (called field config in the UI) you want to modify.
Then obtain a FieldLayoutItem for the field you want to make required.
Then convert the FieldLayout into an EditableFieldLayout, use the makeRequired method on the FieldLayoutItem obtained above and then use the FlieLayoutMangaer to store the object.
Something like this worked for me just now
import com.atlassian.jira.component.ComponentAccessor
def flm = ComponentAccessor.fieldLayoutManager
def project = ComponentAccessor.projectManager.getProjectObjByKey('ASP')
def issueType = ComponentAccessor.constantsManager.allIssueTypeObjects.findByName('Defect')
def fieldLayout = flm.getFieldLayout(project, issueType.id)
def fieldLayoutItem = fieldLayout.getFieldLayoutItem('customfield_10231')
def editable = flm.getEditableFieldLayout(fieldLayout.id)
editable.makeRequired(fieldLayoutItem)
flm.storeEditableFieldLayout(editable)
Thaaanks, worked fine!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.