Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How set a field configuration by groovy script?

Rafael Costa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2022

I would like set some fields as required in a field configuration by groovy script. Someone have any sample code to do it?

1 answer

1 accepted

1 vote
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 4, 2022

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)
Rafael Costa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 5, 2022

Thaaanks, worked fine!!!

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events