Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Referencing the same scripted file

albertogarci86 November 18, 2018

Hi,

I have created an scripted file "FamilyID" that have to check if itself has a previous value. When I reference to the scripted field I received a: java.lang.StackOverflowError

 

This is my code:

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()


CustomField FamilyID = customFieldManager.getCustomFieldObjectByName("FamilyID")



return FamilyID.getValue(issue)

 

Is it possible to reference for the same custom field into an scripted field?

Regards

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
November 18, 2018

You get a stack overflow because your code calls out to get the field which runs your code that calls out to get the field which runs your code that calls out to get the field...

That recursion stops when the process runs out of working space in which to repeat itself.

What you're doing sounds like nonsense to me - a scripted field is there to work something out to display to the user.  By definition, if it has a previous value, it has changed, so it's always going to be trying to work out something.  But, scripted fields don't have a history because they are not data, they're a calculation.

You need to think about what you're really trying to do - I suspect you really mean that you want to look an issue and work out if something on the issue has changed in a way that you need to pull out.

albertogarci86 November 18, 2018

Hi Nic, 

First of all, thanks for your answer. I understand what you explain in your post.

What I am trying to develop is an scripted field that runs when a ticket is cloned. Then the key of the source ticket is copy into a scripted field in the cloned ticket. But if the cloned ticket is cloned again the scripted field gets the source key.

For example:

Ticket1 (FamilyID: null) ---> Clone ---> Ticket 2 (FamilyID: Ticket 1) ----> Clone ----> Ticket 3 (FamilyID: Ticket1)

I share with you the full code:

 

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

List <IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

for (Iterator <IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {

IssueLink issueLink = (IssueLink) outIterator.next();
String linkType = issueLink.getIssueLinkType().getName();

if (linkType == "Cloners"){

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField FamilyID = customFieldManager.getCustomFieldObjectByName("FamilyID")
String FamilyIDValue = issueLink.getDestinationObject().getCustomFieldValue(FamilyID);

Boolean IsSubTask = issueLink.getDestinationObject().isSubTask();

if (IsSubTask == false){

if ( FamilyIDValue?.trim ()){
String key = issueLink.getDestinationObject().getKey();
return key
}else{
return FamilyIDValue
}
}
}

 

This is not working fine. The FamilyIDValue is always empty.

 

Thanks

Nic Brough -Adaptavist-
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.
November 18, 2018

>What I am trying to develop is an scripted field that runs when a ticket is cloned.

Scripted fields show a calculated value, they don't hold data.  They don't "run" during events, the easiest way to think of them is that they calculate the value shown when an issue is indexed.

That said, I can't see that your code is wrong, unless it's not finding the link types or the "family id" field (as long as the family id field is NOT the scripted field itself)

Like albertogarci86 likes this
albertogarci86 November 18, 2018

Yes Nic, that is it. The FamilyID is the scripted field.

So that code is not valid for resolved my problem.

Thanks for the info!

0 votes
albertogarci86 November 18, 2018

To sum up, it is possible to call an scripted field from an scripted field in groovy?

Thanks 

Suggest an answer

Log in or Sign up to answer