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
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)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 '-';
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.