I have a custom field, of type cascading select list, with these values (first -> second):
customer_A - Location1 (one choice)
customer_B - Location2 (two choices)
- Location3
etc.
However, when I select Customer_A in the first drop-down, the second drop-down has None and Location1.
Similarly, choosing Customer_B, I get 3 choices: None, Location2, Location3.
I tried to add a validator on a transaction, using a Simple Scripted Validator from the ScriptRunner add-on.
I tried the following 3 methods (as suggested in various posts), but none works:
cfValues['customfield_17637']?.values()[1].value != Null
cfValues.get('customfield_17637')?.keySet()?.size() == 2 // values are returned as map
cfValues['customfield_17637']?.values()*.value.size() == 2
A co-worker suggested to add an actual value of None and check against it, but I hate this because the user will see 2 None values.
Any idea?
Hey Amir,
Try something like
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException
def issue = issue as MutableIssue
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("CascadingSelect")
def cfValue = issue.getCustomFieldValue(cf) as HashMap
def parentOption = cfValue.values().getAt(0)?.value
def childOption = cfValue.values().getAt(1)?.value
if (!childOption) {
throw new InvalidInputException("Child option is Null")
}
Let me know if this does the trick
Heads up to Amir:
Thanos's solution uses a Custom Validator and not a Simple Scripted Validator.
:D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks to @Thanos Batagiannis [Adaptavist] @Aidan Derossett _Adaptavist_ - it works.
I made a minor modification so that the field name is a constant that can be used more than once:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException
def issue = issue as MutableIssue
final myField = "Account Name and Region"
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(myField)
def cfValue = issue.getCustomFieldValue(cf) as HashMap
def parentOption = cfValue.values().getAt(0)?.value
def childOption = cfValue.values().getAt(1)?.value
if (!childOption) {
throw new InvalidInputException("Error in field '" + myField + "': the second part (region) cannot be empty")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apparently, something changed in ScriptRunner 5.3.7 and later - the hashMap trick no longer work.
Here is what works for me (found it here: LINK)
Map cfValue_acct = issue.getCustomFieldValue(cf_acct) as Map
if (cfValue_acct) {
String acct_acct_name = cfValue_acct.get(null) // get 1st value
String acct_saas_region = cfValue_acct.get("1") // get 2nd value
// do what you want here...
}
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.
please show the full script. Lines 9-10 are obscured
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.
The code works for me. Maybe you're using an older versions? I'm using ScriptRunner 5.3.7 on Jira 7.4.1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error reported above is now happening to me as well, after my ScriptRunner version was updated to 5.3.7. I assume it worked before on an older version that I was using.
If anyone from Adaptavist is watching this thread, please respond.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.