I am trying to create Scripted Field with below script.
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue as Issue; import com.atlassian.jira.issue.fields.CustomField; def CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); // gets a reference to the desired custom field def CustomField cf = customFieldManager.getCustomFieldObjectByName("Time Criticality"); def CustomField cf1 = customFieldManager.getCustomFieldObjectByName("User Business Value"); def CustomField cf2 = customFieldManager.getCustomFieldObjectByName("Risk/Opportunity Value"); // retrieves the custom field value object from the issue def Object cfv = Issue.getCustomFieldValue(cf).toString(); def Object cfv1 = Issue.getCustomFieldValue(cf1).toString(); def Object cfv2 = Issue.getCustomFieldValue(cf2).toString(); return cfv + cfv1 + cfv2;
Above script does not have any compile errors but when executing the same, I am getting below error.
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.issue.Issue.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Time criticality]
Can someone please help me in above script?
Hi,
remove line
import com.atlassian.jira.issue.Issue as Issue;
and use issue instead of Issue
regards
Hello Thanos,
Thanks for quick response. I made the suggested changes and getting java null pointer exception error.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
//import com.atlassian.jira.issue.Issue as Issue;
import com.atlassian.jira.issue.fields.CustomField;
def CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
// gets a reference to the desired custom field
def CustomField cf = customFieldManager.getCustomFieldObjectByName("customfield_21620");
def CustomField cf1 = customFieldManager.getCustomFieldObjectByName("customfield_21621");
def CustomField cf2 = customFieldManager.getCustomFieldObjectByName("customfield_21622");
// retrieves the custom field value object from the issue
def Object cfv = issue.getCustomFieldValue(cf).toString();
def Object cfv1 = issue.getCustomFieldValue(cf1).toString();
def Object cfv2 = issue.getCustomFieldValue(cf2).toString();
return cfv + cfv1 + cfv2;
Can you please help me again?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager def customFieldManager = ComponentAccessor.getCustomFieldManager() // gets a reference to the desired custom field def cf = customFieldManager.getCustomFieldObjectByName("Time Criticality") def cf1 = customFieldManager.getCustomFieldObjectByName("User Business Value") def cf2 = customFieldManager.getCustomFieldObjectByName("Risk/Opportunity Value") // retrieves the custom field value object from the issue def cfv = issue.getCustomFieldValue(cf)?.toString() def cfv1 = issue.getCustomFieldValue(cf1)?.toString() def cfv2 = issue.getCustomFieldValue(cf2)?.toString() return cfv + cfv1 + cfv2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Thanos for providing above script.
Script is working fine without errors but output is not correct. I am getting $value.longValue() as output.
Can you please suggest?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be using the number template. Why are you converting them to strings?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using Select List type fields. Since they are treated as objects I am trying to convert them into string. Correct me if I am wrong
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fine but are the values actually numbers? Or are you trying to concatenate their values?
If they are numbers do something like:
return (cfv as Long) + (cfv1 as Long) + (cfv2 as Long)
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.