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
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.
Hi @Benjamin ,
I already understood that the target field must be visible to the user for the script runner to work.
I'll continue researching how to control the target field to achieve functionality close to what I want, just in terms of user availability (JQL queries only).
Regards,
Isabel Fonseca
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Instead of using "ScriptRunner"\"Behaviours", i resolved the situation with "Listeners".
The field have not screen associate, the listener i create have new code adopted to fill the field, is not visible for users and it is possivel include the field in a JQL (do dashboards, etc). Situation resolved.
Best Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.