Getting first value from cascading select custom field

I'm trying to get the data out of a cascading select custom field, but I'm not having much luck. This code seems to work for getting the value of the second selection, but I can't get at the first:

from com.atlassian.jira import ComponentManager
import urllib
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

customFieldManager = ComponentManager.getInstance().getCustomFieldManager()

# Get the issue number
key = issue.getKey()

# Get value of the 'Revision' field
revisionField = customFieldManager.getCustomFieldObjectByName("Revision")
revision = issue.getCustomFieldValue(revisionField)

# Get value of the 'Domain and Application' field
serviceField = customFieldManager.getCustomFieldObjectByName("Domain and Application")
service = issue.getCustomFieldValue(serviceField)

domain=service['']
application=service['1']

# Kick off the job in Jenkins
params = urllib.urlencode({'SVN_REVISION': revision, 'ISSUE_NUMBER': key, 'DOMAIN': domain, 'APPLICATION': application})
f = urllib.urlopen("http://jenkins/job/flexB-ApplicationService-trunk-jira-test/buildWithParameters?token=flexB-ApplicationService-trunk", params)
print f.read()

This works for getting to the second value (service, or position '1'), but I can't seem to get the first value (domain, or position 'null'). What amm I missing here?

This is a post function in our workflow, and we're running Jira 5.1.4 with Jira Scripting Suite.

Thanks!

Bill

2 answers

1 accepted

0 votes
Accepted answer

following way you can get cascading field value

Object value = issue.getCustomFieldValue(customField);
CustomFieldParams params = (CustomFieldParams) value;
if (params != null) {
Object parent = params.getFirstValueForNullKey();
Object child = params.getFirstValueForKey("1");
}

https://answers.atlassian.com/questions/116569/how-to-get-the-cascading-select-value

or check this issue

https://jamieechlin.atlassian.net/browse/GRV-42

I tried with the script provided, and I get an error message:

root cause: SyntaxError: ("mismatched input 'value' expecting NEWLINE", ('<string>', 19, 7, 'Object value = issue.getCustomFieldValue(10001);\n'))

That portion of my script looks like this:
# Get value of the 'Domain and Application' field
Object value = issue.getCustomFieldValue(10001);
CustomFieldParams params = (CustomFieldParams) value;
if (params != null) {
  Object parent = params.getFirstValueForNullKey();
  Object child = params.getFirstValueForKey("1");

My only real change was to the getCustomFieldValue command. Do I need to make other changes?

Thanks!

Bill

Rambanam gave you groovy/java code, whereas you appear to be using python.

:) Well that would make sense. I'll see if I can re-engineer this. Thanks!

IIRC the value is a nested map, but if you print out the value you will see.

Try service[Null] for the root value - I think python null is "Null".

When I print the value, I get the following:

{null=flexA, 1=MortgageInsurancePremium}

I tried with [null] and [Null], and I get an error either way: Null is not defined. If I use ['null'], it doesn't error out, but the value I get on my jenkins box is "None"

Thanks!

Bill

Sorry, python null is None. Try that, or Rambanam's method which should also work.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,209 views 5 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you