Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,878
Community Members
 
Community Events
184
Community Groups

How to leave a Scripted Field unchanged?

Edited

Hi,

we're running Jira Server with Script Runner 6.5.0.

I have defined a Scripted Field that uses a custom script to calculate a value from another field and a project-specific constant. This works very well.

Now there is a new requirement: the scripted field should only be recalculated if the issue is in a certain state. So I proceed like this:

def statusName = issue.getStatus().getSimpleStatus().getName()
if statusName in ["Status A", "Status B"] {
// calculate newValue
return newValue
}

As long as the issue's is "Status A" or "Status B", this works fine. Unfortunately, if the issue is in a different state, the script returns null, which deletes the field's previous value. But in this case I want to keep the previous value. Unfortunately one cannot get the current value of the field by getValue(issue) to return it, because this leads to a recursion.

Does anyone have a hint for me? Thanks in advance!

Frank

 

1 answer

1 accepted

0 votes
Answer accepted
Gustavo Félix
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.
Sep 22, 2020

Hi @Frank Winkler 
My workaround (I dont know if there's a better way) was saving the scripted field value on another custom field. 
That way I was able to do operations with the previous value. 
In your case, you would have to return the value in the custom field. 
If your scripted field is calculated, update also the custom field.

I hope this gives you an idea.

def statusName = issue.getStatus().getSimpleStatus().getName()
if statusName in ["Status A", "Status B"] {
// calculate newValue
update your custom field with newValue
return newValue
}else{
return yourNewCustomField
}

Hi @Gustavo Félix,

thank you for your the answer - I had already thought along these lines.

But since we already use a lot of custom fields and this requirement involves eight scripted fields, I'm looking for a solution that doesn't require an additional custom field for each scripted field.

Maybe someone from Adaptavist will read along and can give a hint?

Best regards!

Frank

Gustavo Félix
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.
Sep 22, 2020

I hope you find another answer.
Good luck!

Thanks, Gustavo

Hi @Gustavo Félix 

no answer from Adaptavist support - so I implemented your solution using additional custom fields. And it works! Thanks!

regards!

Frank

Like Gustavo Félix likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events