Customfield ID for scripted fields

Eric Brenner July 25, 2014

Hello,

I've got a custom scripted field which returns a value.

In another scripted field, I would like to call this value. I use the following line of code to retrieve it:

CustomField x = customFieldManager1.getCustomFieldObject(FieldID);
double y = issueLink.getDestinationObject().getCustomFieldValue(x);

where FieldID is the customfieldID I found in the config file of the scripted field.

I've used this script before in order to get values like this. I only started running into problems when the customfield ID was for a scripted custom field.

Is it just not possible to retrive that value again? I can't delve into details but I need them as separate scripted fields.

Here's the error I receive:

Cannot cast object 'null' with class 'null' to class 'double'. Try 'java.lang.Double' instead

2 answers

1 accepted

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2014

THis should work fine, but there's not enough info to know why getting the custom field on the linked issue is not working. Are you certain it should not be null for the linked issue?

Eric Brenner July 27, 2014

Yeah, the field should be a number. I'm not sure why it's returning a null, when I open up the "test issue" it's filled in with a number.

Eric Brenner July 27, 2014

I think it has something to do with the way that the customfield is being called through the links... because if I try and call the field without moving through a link I get the number I need. Here is my full code to go through and get it:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager

childFieldID = 10924;
linkTypeID = 10002;
double ChildHours = 0;
CustomFieldManager customFieldManager1 = ComponentAccessor.getCustomFieldManager();
CustomField childField1 = customFieldManager1.getCustomFieldObject(childFieldID);
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();

for (IssueLink issueLink : issueLinkManager.getOutwardLinks(issue.getId())) 
{
 if( issueLink.getIssueLinkType().getId() == linkTypeID )
 {
  double childFieldValue = issueLink.getDestinationObject().getCustomFieldValue(childField1);
  if( childFieldValue != null) 
  {
   ChildHours += childFieldValue;
  }
  else 
  {
   ChildHours += 0;
  }
 }
}

TotalHours = ChildHours;
TotalHours.toString();

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2014

This worked fine for me. I used https://gist.github.com/jechlin/5b1fa2663dfed0b64978

The other field is just a simple scripted field, the script is "2d".

Your field 10924 is another scripted field right? What's the code for that? The problem is probably in that.

Eric Brenner July 28, 2014

The other field is almost identicle... it's basically a way to wrap up hours from multiple issues. Here's the code for the other field.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager

childFieldID = 10123;
linkTypeID = 10002;
double ChildHours = 0;
CustomFieldManager customFieldManager1 = ComponentAccessor.getCustomFieldManager();
CustomField childField1 = customFieldManager1.getCustomFieldObject(childFieldID);
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();

for (IssueLink issueLink : issueLinkManager.getOutwardLinks(issue.getId())) 
{
 if( issueLink.getIssueLinkType().getId() == linkTypeID )
 {
  double childFieldValue = issueLink.getDestinationObject().getCustomFieldValue(childField1);
  if( childFieldValue != null) 
  {
   ChildHours += childFieldValue;
  }
  else 
  {
   ChildHours += 0;
  }
 }
}

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField cf = customFieldManager.getCustomFieldObject(childFieldID)

if( issue.getCustomFieldValue(cf) != null)
{
 ParentHours = issue.getCustomFieldValue(cf);
}
else
{
 ParentHours = 0;
}

TotalHours = ChildHours + ParentHours;
TotalHours.toString();

Is the problem coming from putting it "to.String"?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 28, 2014

I don't know, but if you're summing it you should return a double. Groovy should cast it for you automatically.

Can you describe what these combinations of fields are supposed to do?

Eric Brenner July 28, 2014

When I leave it as a double I get an error stating that the indexer expects a string.

They are designed to wrap up the values from the customfield through multiple layers. Just a single layer is working fine but I would like to add another layer on top of that.

Eric Brenner July 28, 2014

Just realized I had the indexers set for "free text" instead of numbers... it works now! Thanks for your help and sorry to waste your time with something so silly!

0 votes
Eric Brenner July 28, 2014

When I leave it as a double I get an error stating that the indexer expects a string.

They are designed to wrap up the values from the customfield through multiple layers. Just a single layer is working fine but I would like to add another layer on top of that.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events