Forums

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

Hide a field

Isabel Fonseca August 27, 2025

Hi,

In Jira data center v9.12.19, the "Related Projects" custom field type Database Picker.

The "Related ProjectsList" custom field type Select List(multiple choices).

>Main Goal: Copy value(s) from one field to another. The "Related Projects List" field is available to do Search for issues by JQL.

>The behaviour bellow, works with success:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.onresolve.scriptrunner.db.DatabaseUtil
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.db.DatabaseUtil

@BaseScript FieldBehaviours fieldBehaviours

// --- LOGGER SETUP --- //
def log = Logger.getLogger("com.acme.scriptrunner.SelectListUpdater")
log.setLevel(Level.DEBUG)

def optionsManager = ComponentAccessor.getOptionsManager()
def fieldLayoutManager = ComponentAccessor.fieldLayoutManager
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager

// FIELD A -> Database Picker (source) id=31801
def fieldRelatedProjects = "Related Projects"
// FIELD B -> Select List (multiple choice) id=37200
def fieldRelatedProjectsList = "Related ProjectsList"

// ! FIELD A ###################################### :
def dbPickerCf = customFieldManager.getCustomFieldObjectsByName(fieldRelatedProjects).first()
def field_RP = getFieldById(dbPickerCf.id as String)
def selectedIds = field_RP.getValue()

log.debug("User selected IDs in DB picker: ${selectedIds}")

// ! FIELD B ###################################### :
// Set a fixed values FIELD B. TO DO: get from FIELD A
def selectListField = getFieldByName(fieldRelatedProjectsList)
//selectListField.setFormValue("P00014-OD Training")
//log.info("FIELD B) Valor conforme FIELD A) TO DO")

// --- Lookup description(s) for selected ID(s) ---
def descriptions = []

if (selectedIds) {
def ids = (selectedIds instanceof List) ? selectedIds : [selectedIds]
log.debug("ids: ${ids}")

DatabaseUtil.withSql("SGI") { db ->
ids.each { idVal ->
def row = db.firstRow("SELECT [I2SSGI].[dbo].[Projeto].[Nome] as nome FROM [I2SSGI].[dbo].[Projeto] JOIN [i2SSGI].[dbo].[ProjetoRefContabilistica] ON [i2SSGI].[dbo].[ProjetoRefContabilistica].[Id] = [I2SSGI].[dbo].[Projeto].[Id]where [I2SSGI].[dbo].[Projeto].EstadoId = 1 AND [I2SSGI].[dbo].[ProjetoRefContabilistica].[RefContabilistica] = ?", [idVal])
if (row?.nome) {
descriptions << row.nome.trim()
}
}
}
}

log.debug("Resolved descriptions: ${descriptions}")

// --- Set into FIELD B ---
if (descriptions) {
// For multi-select: pass list
selectListField.setFormValue(descriptions)
} else {
selectListField.setFormValue(null) // clear if nothing
}

 

 

>To Do/Help:
The "Related Projects List" , is possible to hide from user and the behaviour still works?

(I tried several things but it doesn't work: remove field from screen; include in behaviours selectListField.setHidden(true); Jira Adminintration\Issues\Field Configuration\Hide field)

Many thanks,

Isabel Fonseca

1 answer

0 votes
Benjamin
Community Champion
August 27, 2025

Hi @Isabel Fonseca ,

 

Welcome. If I understood correctly, you want to try to hide the field and you still want to copy the value? How will the field be populated if the field is hidden from users?

Might trying below:

1. You the hide field option in behaviors. Referring to the toggle button.

2. You can have a condition in the behavior once the destination field has been populated with the copy values or isn't empty, hide the source field. 

 

 

Suggest an answer

Log in or Sign up to answer