You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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.
We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan. &nb...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.