Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,464,402
Community Members
 
Community Events
176
Community Groups

Using Scriptrunner to return custom field value

Hi

I'm trying to use Scriptrunner to (in part) get the value of a custom field. However, at the moment I am getting an error.

This is what I am trying to do, to get the value.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

return getCustomFieldValue("Change Area")

When I do this, I get this error:

2017-11-21 12:30:12,374 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2017-11-21 12:30:12,375 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Change Area] at Script160.run(Script160.groovy:9)

 

I am a complete noob, so apologies if I am making an obvious mistake. Can someone point out the error of my ways?

Best wishes

 

1 answer

1 accepted

1 vote
Answer accepted

Hello, 

You would need a script like this

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("issuekey")
def csChangeArea = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Change Area")

return issue.getCustomFieldValue(csChangeArea)

Hi @Alexey Matveev _Appfire_ 

Recently I have upgraded my JIRA from v7.9.2 to v8.2.5.

Also, I have updated the script runner plugin from v5.4.49 to v5.6.2.1-jira8.

Please find my below script and error output.

import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;

Issue issue = issue

def issueKey = issue.getKey()

def supp_tkt_cnt = getCustomFieldValue("Support Tickets")

if(supp_tkt_cnt > 0){
String url = "https://solutions.com/web/modules/pss/crm/css/op/CCSSReportedCustDetailsModViewMgr.php?strTCMIssueIDs=" + issueKey;

return "<a href=\"" + url + "\">" + url + "</a>";
}
else{

return '-';
}

 

Output Error Log:

2019-09-30 17:38:50,193 ERROR [runner.ScriptFieldPreviewRunner]: *****************************
2019-09-30 17:38:50,193 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Support Tickets]
at Script683096.run(Script683096.groovy:12)

Note: The fields are available in JIRA.

Like Damien Davis likes this

Hello @Prasad Andrews, that doesn't seem like the way to pick up the value of a custom field. Please try the following code:

import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;

Issue issue = issue

def issueKey = issue.getKey()
def supp_tkt = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Support Tickets")
def supp_tkt_cnt = (double) issueKey.getCustomFieldValue(supp_tkt)

if(supp_tkt_cnt > 0){
    String url = "https://solutions.com/web/modules/pss/crm/css/op/CCSSReportedCustDetailsModViewMgr.php?strTCMIssueIDs=" + issueKey;
    return "<a href=\"" + url + "\">" + url + "</a>";
}
else {
    return '-';
}

 

Like Prasad Andrews likes this

Hi All,

I need some help. How to get the value of the custom field from the issuetype. Then printing and using that variable further.

I have a issue type with name "TEST1-5". when trying to print the value for issue and csChangeArea i am getting "NULL" value. Please help.

When 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST1-5")
def csChangeArea = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Username")

log.info("My script variable new value : " + issue)

log.info("Custom field value : " + csChangeArea)

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events