Forums

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

Behaviours can't set CustomFields with Context hidden

Benjamin Krüger
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 10, 2022

Hello,
we have a transition where I can create a ticket to other teams. There, with the help of Behaviours, the fields for the corresponding project are displayed.

My script correctly pulls all these fields, but cannot display the fields that have a Context.

import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.screen.FieldScreenTab
import com.atlassian.jira.issue.fields.screen.FieldScreenLayoutItem
import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.issue.fields.screen.FieldScreen
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor


@BaseScript FieldBehaviours fieldBehaviours
def kollabArt = getFieldById("customfield_15300")
def team = getFieldById("customfield_15301")

FieldScreenManager fieldScreenManager = ComponentAccessor.getFieldScreenManager()
List <FieldScreenTab> fieldScreenTabs = []
List <FieldScreenLayoutItem> fieldScreenItems = []
List <FormField> screenFieldList = []

//Hide all cF
List <CustomField> allCf = ComponentAccessor.getCustomFieldManager().getGlobalCustomFieldObjects()
allCf.each{ field ->
FormField cF = getFieldById(field.getId())
cF.setHidden(true)
}
kollabArt.setHidden(false)


//Hide all standard Fields
List <String> standardF = ["components", "attachment", "description", "labels", "issue type", "priority", "reporter", "assignee", "due date", "comment", "summary"]
standardF.each { field ->
getFieldById(field).setHidden(true)
}
 

//method to get all Fields for Create
public void showFieldsOnScreen(long id, List<FieldScreenTab> fieldScreenTabs, List<FieldScreenLayoutItem> fieldScreenItems, List<FormField> screenFieldList) {
fieldScreenTabs = fieldScreenManager.getFieldScreenTabs(fieldScreenManager.getFieldScreen(id))
fieldScreenItems = fieldScreenManager.getFieldScreenLayoutItems(fieldScreenTabs.get(0))
fieldScreenItems.each{ items ->
FormField field = getFieldById(items.getFieldId())
screenFieldList.add(field)
}
screenFieldList.each{ cF ->
cF.setHidden(false)
}
}


switch(team.value){
case "XXX":
switch(kollabArt.value){
case "YYY":
case "ZZZ":
showFieldsOnScreen(12201, fieldScreenTabs, fieldScreenItems, screenFieldList)
break;
}
break;  
}

 

All other CustomFields are hidden/shown correctly. How can i do it if these CustomFields are having context?

1 answer

0 votes
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.
November 10, 2022

You need to add the current project to the context or create a separate context for the current project. Note that if the field has options, and you create a separate context, the options may not be the same.

Also, what you are doing may not work all that well. Have you checked that after adding the fields, the screen layout is not permanently modified?

I would start by ensuring all the fields you want are visible on the screen by manually adding them and configuring them in the context and in the field config so they are visible. All while all behaviours are disabled.

Then, add the behaviour back to just hide the fields that are not needed for a specific condition.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events