I'm using Adaptivist Scriptrunner. I need to clear both values within a cascading custom field when an issue transitions into IN PROGRESS. I can't figure out how to do this, and I can't see any examples on the Adaptivist site.
Can anyone give me a step by step guide? The simpler the better, as this is something I have very little experience of. Actual code where I can just substitute field names would be ideal!
Edit: No "you can do it using this paid for app" answers please.
I can paste those scripts, after verifying for myself they work (probably a year or so since I touched a cascading field so also want to refreshen up on that).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alright I think this should be it:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
OptionsManager optionsManager = ComponentAccessor.getComponent(OptionsManager)
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cascadingCF = customFieldManager.getCustomFieldObjectsByName("Activity").find {
it.getCustomFieldType() instanceof CascadingSelectCFType
}
if (!cascadingCF) {log.error("Cannot find cascadingCF field! Exiting."); return}
MutableIssue mutableIssue = (MutableIssue) issue
// to get parent value: currentValues.get(null)
// to get child value: currentValues.get("1")
Map<Object, LazyLoadedOption> currentValues = issue.getCustomFieldValue(cascadingCF) as Map<Object, LazyLoadedOption>
//Need to decide here which block you want to use in your use case
if (currentValues == null) { //is empty, set values
FieldConfig fieldConfig = cascadingCF.getRelevantConfig(mutableIssue)
Option parentOptionToSet = optionsManager.getOptions(fieldConfig).getOptionForValue("Parent 1", null) //(String optionName, long parentOptionId), so this is for parent
Option childOptionToSet = optionsManager.getOptions(fieldConfig).getOptionForValue("Child 1.1", parentOptionToSet.getOptionId()) //and this for child
Map<Object, Option> optionsToSet = new HashMap<Object, Option>() {
{
put(null, parentOptionToSet)
put("1", childOptionToSet)
}
}
mutableIssue.setCustomFieldValue(cascadingCF, optionsToSet)
}
else { //list is not empty, clear it
mutableIssue.setCustomFieldValue(cascadingCF, null)
}
Let me know in case this gives you any trouble or if you have any questions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Note that in workflow post-functions, this should be before "issue updated, added to changelog, yadayada" and re-index. So ideally somewhere near to top, either before or after "Status changed to destination step" one.
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.
Ok that worked perfectly. Thanks so much for your time and effort, hugely appreciated.
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.