Hi all,
I am trying to write some groovy code to update custom fields. I have written code to update custom field names, descriptions (using CustomFieldManager) and options (using OptionsManager). However I am trying to update the Field Configuration to be 'Required' (see attached image) but I cannot find any documentation on how to do this. I've checked FieldConfigSchemeManager but there is nothing in here which seems to indicate this is possible.
Looking at the UI for editing a Field Config Scheme, it seems like I want to trigger EditFieldLayoutRequire.jspa for the required field.
Any replies are appreciated, thank you
Solved! Go to Solution.
Here's a simple snippet how this can be done
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.layout.field.EditableFieldLayout
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutManager
// stuff
final String FIELD_TO_MODIFY = "summary"
final String fieldConfigurationName = "<Field Configuration Name>"
// get stuff
FieldLayoutManager fieldLayoutManager = ComponentAccessor.getComponent(FieldLayoutManager)
EditableFieldLayout editableFieldLayout = fieldLayoutManager.getEditableFieldLayouts().stream().filter({ efl -> efl.getName() == fieldConfigurationName }).findAny().orElse(null)
List<FieldLayoutItem> fieldLayoutItems = editableFieldLayout.getFieldLayoutItems()
FieldLayoutItem fieldLayoutItem = fieldLayoutItems.stream().filter({ i -> i.getOrderableField().getId() == FIELD_TO_MODIFY }).findAny().orElse(null)
// do stuff
editableFieldLayout.makeRequired(fieldLayoutItem)
// save stuff
fieldLayoutManager.storeAndReturnEditableFieldLayout(editableFieldLayout)