Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get a string value from a drop down custom field

mesher23
November 29, 2018

Hello! The situation is this: I need to output the selected string value from the child's drop-down list to another field. here is the code

<code>

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.Issue


def IssueManager issueManager = ComponentAccessor.getIssueManager();


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfNFeed = customFieldManager.getCustomFieldObject('customfield_12404')
def direction = issue.getCustomFieldValue(cfNFeed)

def v_bus_direction = direction.split(';')[0]
def bus_direction = v_bus_direction.split(':')[1]
def v_work_direction = direction.split(';')[1]
def work_direction = v_work_direction.split(':')[1]
def v_type_work = direction.split(';')[2]
def type_work = v_type_work.split(':')[1]

String parent_new_value = bus_direction.toString() + ": " + work_direction.toString()
String children_new_value = type_work.toString() - "]"

def changeHolder = new DefaultIssueChangeHolder()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11117")
def fieldConfig = customField.getRelevantConfig(issue)
def parentOption = ComponentAccessor.getOptionsManager().getOptions(fieldConfig)?.find { it.toString() == parent_new_value }
def childOption = ComponentAccessor.getOptionsManager().findByParentId(parentOption.optionId)?.find { children_new_value }

def newValue = [:]
newValue.put(null, parentOption)
newValue.put("1", childOption)
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), newValue),changeHolder)

</>

All i need is to transfer

 

children_new_value



to view here

newValue.put("1", childOption)

 thanks!image.pngimage.png

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
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 Champions.
April 15, 2014

Michele - there is information on this here: https://jamieechlin.atlassian.net/wiki/display/GRV/Upgrading+to+3.0(under "script roots" section) - but it's only pertinent to the new beta version.

You can download it from the same page if you have a recent enough jira instance.

For the current version you need to compile a jar really, although I would recommend trying the new version as using dependent classes and libraries will be much easier.

David Turner
June 19, 2014

Hi Jamie,

Running Jira 6.2.2 on Windows. Had a post-function and listener-enabled class in package com.onresolve.jira.groovy.canned.workflow.postfunctions.

Just upgraded Script Runner 2.2.x to to 3.0-b11 in order to get Behaviours function back, and now when I view ScriptRunner Listeners, I see an 'undefined' value and getting an error in atlassian-jira.log:

2014-06-20 15:28:47,401 ajp-apr-8009-exec-9 ERROR &lt;user&gt; 928x25038x2 6mf16d &lt;ip&gt; /rest/scriptrunner-jira/latest/listeners [scriptrunner.runner.rest.AbstractRestEndpoint] Could not get script name:
groovy.util.ResourceException: Malformed URL: bundle://177.0:0/, null
    at groovy.util.GroovyScriptEngine.getResourceConnection(GroovyScriptEngine.java:373)    at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:513)

Caused by: groovy.util.ResourceException: Malformed URL: file:/C:/Tools/Atlassian/JIRA-Data/scripts/, null

Naturally, this is referring to the newly created 'script-root' directory introduced in 3.0.

Attempting to resolve, I've just moved my old post-function script (with full path) into the new 'scripts' directory and added "-Dplugin.script.roots=C:\Tools\Atlassian\JIRA-Data\scripts" to Java Opts (but not changed classpaths yet).

But this hasn't helped. Same error.

Any ideas?

David Turner
June 19, 2014

Seems adding Dplugin.script.roots was unnecessary; now that default path is included twice (if Script Console is anything to go by).

Hmm, hope I'm not going bonkers but it looks like the scriptrunner utility groovies/classes etc have moved to a new package/path; if so this might need to be noted on the 3.0 pages!?

From 2.2: com.onresolve.jira.groovy.canned.*

Now 3.0: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions
com.onresolve.scriptrunner.canned.jira.utils etc?

I'll need to adjust imports and try again.

EDIT: -- Yep, that's done it. Adjusted the packages and my class now appears in the Script Listeners list again. Bril. :)

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 Champions.
June 22, 2014

David - yes, some packages were moved, sorry about that but I didn't have much choice. I need to document that.

I will make it so that it doesn't add the path twice...

I'm not really sure why you got the malformed url exception though, looks ok.

0 votes
Paresh Gandhi
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 Champions.
April 14, 2014

try below exmple:

import com.atlassian.jira.event.issue.AbstractIssueEventListener

class JiraLibrary extends AbstractIssueEventListener {

@Override

void issueUpdated (IssueEvent event) {

}

}

TAGS
AUG Leaders

Atlassian Community Events