Hi all. Faced the problem of updating the options of the custom field of the cascading list. We have a third party system that contains a directory:
- Parent 1
-- child 1
-- child 2
- Parent 2
-- child 1
We update the custom field through the Scriptrunner, below is part of the update code.
def issue = ComponentAccessor.issueManager.getIssueObject('OTHER-205')
CustomField PROGRAM_FIELD_NAME = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10244")
def om = ComponentAccessor.optionsManager
def options = om.getOptions(PROGRAM_FIELD_NAME.getRelevantConfig(issue))
def programs = Config.serviceDeskClient.sendGetRequest()
def temp = new HashMap<String, Program>(programs)
programs.entrySet().each {
def currentOption = options.find { op -> op.value.startsWith(it.key) }
if (currentOption.collect().size() == 1) {
currentOption.setValue(it.value.name)
it.value.subPrograms.each { sub ->
def currentChild = currentOption.childOptions.find { ch -> ch.value.startsWith(sub.key) }
if (currentChild.collect().size() == 1) {
currentChild.setValue(sub.value.name)
} else {
om.createOption(PROGRAM_FIELD_NAME.getRelevantConfig(issue), currentOption.optionId, (long) (currentOption.childOptions.size() + 1), sub.value.name)
}
}
} else {
om.createOption(PROGRAM_FIELD_NAME.getRelevantConfig(issue), null, (long) (options.childOptions.size() + 1), it.value.name)
}
}
om.updateOptions(options)
options.each {
log.error "${temp.containsKey(it.value.substring(0, 3)) && !Character.isDigit(it.value.substring(4, 5).charAt(0))}"
if (temp.containsKey(it.value.substring(0, 3))
&& !Character.isDigit(it.value.substring(4, 5).charAt(0))) {
it.childOptions.each { ch ->
if (!programs.get(it.value.substring(0, 3)).subPrograms.containsKey(ch.value.substring(0, 6))
|| !temp.get(it.value.substring(0, 3)).subPrograms.containsKey(ch.value.substring(0, 6))) {
om.disableOption(ch)
om.deleteOptionAndChildren(ch)
} else {
temp.get(it.value.substring(0, 3)).subPrograms.remove(ch.value.substring(0, 6))
log.error "Exception return"
return
}
}
} else {
log.error "DIASBLE OPTION ${it.value}"
om.disableOption(it)
om.deleteOptionAndChildren(it)
temp.remove(it.value.substring(0, 3))
}
}
om.updateOptions(options)
As a result, we get the following picture.
1. In the general list of options, a new value. pic 2
2. In option edit mode, the old value. pic 3
3. In the "view" task, the old value. pic 4
4. In the task to "edit" the new value. pic 5
The database stores the old value. Tried to index task/project/full reindex. A full reindex returns the old value.
Maybe someone faced similar?
Problem solved. It is necessary after updating both the parent and child options to run option.store():
parentOption.store();
childOption.store();
Because in the database they are stored in different rows as separate objects.
Could you please clarify if you are trying to do this via ScriptRunner Behaviour or Listener or Post Function?
If it is via Behaviour, then the approach doesn't seem to be correct. Could you also pleases share a screenshot of your Behaviour configuration if you are doing this via Behaviour?
Also, what version of Jira and ScriptRunner are you using?
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good afternoon. This is done via REST Endpoints. The logic is such that a third-party service, while updating options on its own, sends a request to Jira and Jira already receives data for new options from a third-party service and edits its own.
This is done in order to update the data in the Jira as quickly as possible and so that the third-party service understands that the data in the Jira has been updated.
Jira Version 8.22.3 DC
Version Scriptrunner 8.0.0
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.