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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.