Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 _cPrime_ 

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

103 views 0 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you