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.ComponentAccessordef flm = ComponentAccessor.fieldLayoutManagerdef 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!!!
It looks like you're new here. Sign in or register to get started.