Calculated custom field script is not working

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?

1 answer

1 accepted

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?

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

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 using the number template. Why are you converting them to strings?

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

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)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

476 views 7 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you