Customfield ID for scripted fields

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

This widget could not be displayed.

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?

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.

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();

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.

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"?

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?

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.

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!

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

536 views 3 19
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