The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How to make a field 'Required' for a particular field configurations using groovy?

Samuel Holley
November 23, 2023

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.

fieldconfigedit.JPG

Any replies are appreciated, thank you

2 comments

Comments for this post are closed

Community moderators have prevented the ability to post new comments.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 23, 2023

Hi @Samuel Holley

Welcome to the Community.

Could you please provide a little more information, i.e., when do you want the field to be updated? Is it on the Create / Edit screen or after the issue transitions to a different status?

If it is on the Create / Edit screen, ScriptRunner Behaviour would be the best approach. 

Also, please specify exactly the field types you are using to trigger the change. I am asking this so I can provide an example code.

Thank you and Kind regards,

Ram

Radek Dostál
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 Champions.
November 23, 2023

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)
Like Samuel Holley likes this
Samuel Holley
November 23, 2023

This has worked, thank you!

TAGS
AUG Leaders

Atlassian Community Events