Getting first value from cascading select custom field

Bill Wonch August 4, 2013

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
Answer accepted
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2013

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

Bill Wonch August 5, 2013

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 5, 2013

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

Bill Wonch August 5, 2013

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

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2013

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".

Bill Wonch August 4, 2013

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 4, 2013

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