Forums

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

Scriptrunner console get the value of a customfield

Mahdi Challouf
Contributor
December 12, 2018

I have a custom field of type project picker and i want to get the value selected, here my code 

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.project.Project

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11001");// ID of my custom field.

def value = (String)issue.getCustomFieldValue(customField);
log.info("the project selected is"+value)

 

and i get an error : the variable issue is undeclared 

any help !!

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
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.
July 13, 2018

Hi Damon,

What version of SR are you on? You might try this instead:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.onresolve.scriptrunner.canned.jira.utils.ConditionUtils
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue

def issue = ComponentAccessor.getComponent(IssueManager).getIssueByKeyIgnoreCase("SRC-1")
def clonesId = ComponentAccessor.getComponent(IssueLinkTypeManager).getIssueLinkTypes().findByName("Cloners")?.id

def cloneIssue = new CloneIssue()

def additionalCode = """
issue.setSummary("CLONED: " + issue.getSummary())
checkLink = {link -> link.issueLinkType.name != "Cloners"}
"""

Map<String, Object> inputs = [
issue : issue,
(ConditionUtils.FIELD_ADDITIONAL_SCRIPT): [additionalCode, ""],
(CloneIssue.FIELD_COPY_COMMENTS) : true,
(CloneIssue.FIELD_TARGET_PROJECT) : "DEST",
(CloneIssue.FIELD_LINK_TYPE) : clonesId + " inward",
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
] as Map<String, Object>

def errorCollection = cloneIssue.doValidate(inputs, false)
if (errorCollection.hasAnyErrors()) {
log.warn("Couldn't clone issue: ${errorCollection}")
}
else {
cloneIssue.doScript(inputs)
}
Damon Osgood
July 13, 2018

Adaptavist ScriptRunner for JIRA 5.4.12

Yes, that did the trick! Thank you!

How did you know that, btw? Is there documentation that would have told me that the interface seems to have changed at some point?

Joshua Yamdogo @ Adaptavist
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.
July 13, 2018

Hi Damon,

That's a good question. I took a quick look at our documentation and I don't see an example of CloneIssue being used manually, so I don't think you would have known about any changes. I can see how that would be frustrating!

The problem here, in my opinion, is that running CloneIssue manually is something we don't particularly want everyone to do, so it's not likely to end up in the documentation. It can be difficult to use and often creates more problems for users than it solves, since the built-in clone script is often "good enough." Only in niche cases do we recommend doing it, such as in your situation.

In any case, if you run into a problem like this again, I'd suggest submitting a support request through our Service Desk portal here: https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=server&tab=support

Regards,

Josh

Damon Osgood
July 13, 2018

Thanks again.

slothstronaut
Contributor
February 6, 2019

Hi Joshua Yamdogo @ Adaptavist , 

 

is there a full documentation out there in the internetz about the possible map values of the CloneIssue params? 

 

CloneIssue.FIELD_COPY_COMMENTS
CloneIssue.*WHAT CAN I DO HERE ¯\_(ツ)_/¯ *

 

 

Thanks for your time, 

cheers

slothy  

Like # people like this
TAGS
AUG Leaders

Atlassian Community Events