Hey,
I am writing a listener script for Jira that updates the value of a cascading field from a text field.
I am able to pull the value from the text field but I am not sure how to set them to the cascading fields. I found a guide online but it does not seem to work https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/setting-default-fields.html#_setting_cascading_select_values
I am getting an error on getFieldByName(fieldName), the error says this method does not exist.
I have not been able to find any solution for this online.
The link you have applies to Behaviours (part of SR) but not other parts of SR, like Scripted Listeners.
You'll want to use groovy like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def changeHolder = new DefaultIssueChangeHolder()
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey('SPB-5')
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10600)
def fieldConfig = customField.getRelevantConfig(issue)
def parentOption = ComponentAccessor.getOptionsManager().getOptions(fieldConfig)?.find { it.toString() == 'North America' }
def childOption = ComponentAccessor.getOptionsManager().findByParentId(parentOption.optionId)?.find { it.toString() == 'USA' }
def newValue = [:]
newValue.put(null, parentOption)
newValue.put("1", childOption)
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue),changeHolder)
See OptionsManger API documentation for more details on how to get options.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hallo togther,
I tried quite the same and my cascading field isn't updated with this code.
I update this field within the Standard-Function of scriptrunner "Clones an issue, and links" in the field additional issue actions. You see in the code, that I also set the summary, which works.
For the code above I don't receive any errors in the log after processing.
The log-output which I added to control if everythings fine also delivered the values, I expexcted:
2019-02-26 12:39:29,487 ERROR [utils.ConditionUtils]: parentOption:SAP 2019-02-26 12:39:29,489 ERROR [utils.ConditionUtils]: childOption:Berechtigung 2019-02-26 12:39:29,489 ERROR [utils.ConditionUtils]: customFieldName:Vorgangskategorie 2019-02-26 12:39:29,489 ERROR [utils.ConditionUtils]: customFieldId:customfield_12803 2019-02-26 12:39:29,491 ERROR [utils.ConditionUtils]: customFieldKey:Vorgangskategorie 2019-02-26 12:39:29,492 ERROR [utils.ConditionUtils]: fieldConfig:com.atlassian.jira.issue.fields.config.FieldConfigImpl@b7a27a59 2019-02-26 12:39:29,492 ERROR [utils.ConditionUtils]: 0:SAP 2019-02-26 12:39:29,492 ERROR [utils.ConditionUtils]: 1:Berechtigung
The only thing is, that the update in the cloned issue isn't updates.
This is my Code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
issue.summary = 'SAP Berechtigungen für ' + issue.summary
def changeHolder = new DefaultIssueChangeHolder()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12803)
//def customField = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Vorgangskategorie'}
def fieldConfig = customField.getRelevantConfig(issue)
def parentOption = ComponentAccessor.getOptionsManager().getOptions(fieldConfig)?.find { it.toString() == 'SAP' }
def childOption = ComponentAccessor.getOptionsManager().findByParentId(parentOption.optionId)?.find { it.toString() == 'Berechtigung' }
log.error("parentOption:" + parentOption)
log.error("childOption:" + childOption)
log.error("customFieldName:" + customField.getName())
log.error("customFieldId:" + customField.getId())
log.error("customFieldKey:" + customField.getNameKey())
log.error("fieldConfig:" + fieldConfig)
//def newValue = [:]
def newValue = new HashMap();
newValue.put(null, parentOption);
newValue.put("1", childOption);
log.error("0:" + newValue.values().getAt(0));
log.error("1:" + newValue.values().getAt(1));
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue),changeHolder)
Could you please help me further.
Thanks in advance.
Dominik
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.