The "easiest" is to pass the Option ID as a string. The Option ID is visible at the end of the "Edit" link on the Edit Options screen of the cascading custom field.
If the child option's textual value is unique in the entire cascading field's values, you can also pass that value.
We will also make it easier to set cascading field values in an upcoming version of JMWE.
David
Can you give me an example of the expression i would use? I normally just set the field and do a raw value of what i want it to be.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If it's a constant value you want to set, you go to the configuration of the cascading custom field, navigate to the appropriate parent value, and then click on the Edit link for the child value:
Capture d’écran 2016-09-23 à 15.09.42.png
Capture d’écran 2016-09-23 à 15.12.55.png
Then you look at the URL of the page. At the end, you should see something like: &selectedValue=10102. 10102 would then be the value you type in the Value field of the post-function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then it would just literally tell the field to set to that numeric value, right? It did not work when I tried it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It would set the field to the value whose ID is that numeric value, yes. I'm surprised it didn't work, I'll need to test it further.
You didn't select "Groovy", did you?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did not select Groovy. I did raw value. I'm not sure what i am doing wrong here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, I just tested it and it is indeed a regression related to JIRA 7.
However, you can still set a value on a cascading select field, but the code is rather complicated:
import com.atlassian.jira.component.ComponentAccessor; def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(10000); def childOptionObj = optionsManager.findByOptionId(10002); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); newValues.put("1", childOptionObj); return newValues;
where 10000 and 10002 are the IDs of the parent and child options.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So would I just put all of that in the box and change it to Groovy instead of Raw Value?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Exactly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome! So for times when there is no child, I guess it would be the default "None" option, how can I tell it to only set the parent?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I changed mine to remove the child option obj and change the newValues, but it is not working currently.
import com.atlassian.jira.component.ComponentAccessor; def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19248); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put("Help Desk", parentOptionObj); newValues.put(null, childOptionObj); return newValues;
Even when I leave that info in it does not seem to work:
import com.atlassian.jira.component.ComponentAccessor; def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(18683); def childOptionObj = optionsManager.findByOptionId(19247); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put("ERP", parentOptionObj); newValues.put("EDI", childOptionObj); return newValues;
I actually get an error with it when I try to trigger it with the transition button.
"Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.util.HashMap cannot be cast to java.util.Collection
It seems that you have tried to perform an illegal workflow operation.
If you think this message is wrong, please contact your JIRA administrators."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The first parameter (the "key") of the put() method is always null for the parent value, and "1" for the child value. Never change them.
To set just the parent value, I believe you just omit the child ("1") value:
import com.atlassian.jira.component.ComponentAccessor; def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19248); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); return newValues;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh wow, I see now. That worked perfectly! Thank you very much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One more quick thing and I should be all set. What if I want it to be used in an if statement? So it would set the cascading field to one thing based on a certain issue type, but if it is not that issue type it would not.
Here is what I have tried so far:
import com.atlassian.jira.component.ComponentAccessor; if (issue.issueTypeObject.name == "Account Administration"){ def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19239); def childOptionObj = optionsManager.findByOptionId(); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); newValues.put("1", childOptionObj); return newValues; } else { def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19248); def childOptionObj = optionsManager.findByOptionId(); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); newValues.put("1", childOptionObj); return newValues; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your code is moving in the right direction except that "def childOptionObj = optionsManager.findByOptionId();" won't work because you need to pass an Option ID. If you don't need a child option, just don't create that variable and don't put it into the Map.
When you code doesn't work, always look into your JIRA logs (atlassian-jira.log) for ERRORs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, even when I remove that it does not work. I have checked the log you mentioned, but all it says is that there was an error dealing with a Groovy script, not what is actually wrong.
My current code:
import com.atlassian.jira.component.ComponentAccessor; if (issue.issueTypeObject.name == "Account Administration"){ def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19239); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); return newValues; } else { def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19248); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); return newValues; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, the ERROR should tell you what's wrong. But be careful, it's a multi-line error description so "grep" won't work.
In your particular case, I think the error (mine, actually) is on the following line (repeated twice):
Map<String,Object> newValues = new HashMap<String, String>();
It should be
Map<String,Object> newValues = new HashMap<String, Object>();
or even simpler:
def newValues = new HashMap();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey David,
I know this question is old, but I thought I might post here. I am having the same issue.
My code:
import com.atlassian.jira.component.ComponentAccessor; if (issue.get("customfield_18871") != "1" || issue.get("customfield_18871") != "2" || issue.get("customfield_18871") != "3"){ def optionsManager = ComponentAccessor.getOptionsManager(); def parentOptionObj = optionsManager.findByOptionId(19472); def childOptionObj = optionsManager.findByOptionId(19488); Map<String,Object> newValues = new HashMap<String, String>(); newValues.put(null, parentOptionObj); newValues.put("1", childOptionObj); return newValues; }
It just makes this field always have this value. Even if 1,2, or 3 is selected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You want an "and" ("&&"), not an "or" (||) between the conditions.
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're right... My logic was just messed up in my head. You are the best! Thanks so much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.