You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I am new to Scriptrunner so bear with me... I am trying to set the value of a custom field based on the value of another custom field. When I make the change to the issue I can see that the secondary field is updating, however I don't see this change for a while in my filters. They still display the original field values. Eventually they catch up. Is there some sort of time delay in propagating these changes to the filters? I don't really understand what is going on. Here is my code:
def ClosureCode = getFieldByName("Closure Code") def piReview = getFieldByName("PI Review") def ClosureCodeValue = ClosureCode.getFormValue(); def piReviewValue = piReview.getFormValue(); log.error("TEST LOG BEHAVIOR") log.error("Closure Code is "+ClosureCodeValue) log.error("PI Review is "+piReviewValue) log.error("TEST LOG BEHAVIOR") if (ClosureCodeValue=="11314") //Successful set to N/A { log.error("Successful closure code") (piReview=="11328") piReview.setFormValue("11328") } if (ClosureCodeValue=="11316") // Unsuccessful set to pending { log.error("Unsuccessful closure code") (piReview=="11341") piReview.setFormValue("11341") }
I am not sure which of the two methods is correct to set the value so i am using both....
I disagree with Juan ... with Behaviours, there is no indexing impact. The form fields are updated live in your browser just like a human would using keyboard and mouse.
When you submit the form, the changes are stored in the DB and the index is refreshed.
Do you see similar delays for changes you make manually appearing in the filter? If so, I'd investigate for something wrong with the automatic indexing processes.
Btw.. this does nothing:
(piReview=="11328")
Thanks for tips @Peter-Dave Sheehan , I removed the code that does nothing. I will add some images that show what is going on... very strange. When closure code is successful I am setting PI Review to "N/A" in Scriptrunner since we don't need to review successful changes in our CAB meetings.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just noticed if I open the issue to edit and press "Update" without changing ANYTHING, the filter will display properly. It is as if Scriptrunner is not getting the tables to update properly - I really haven't a clue...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you view the PI Review value after the change is applied by behaviour and you submit the form in the issue view? Does it show the new value?
What about in the change history tab?
I can't see why it would make a difference, but can you try to change
piReview.setFormValue("11328")
to
piReview.setFormValue(11328L)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan , I only see the change in the history tab after I press the update button, not after the value is changed by the behaviour.
I also changed form value to 11328L - no difference
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My original observation "Eventually they catch up." was not accurate, it was probably just that I had updated the form and didn't attribute that to the catch up
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a way to force the update after changing the value in Scriptrunner? That may do the trick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What you are experiencing just makes no sense to me ... Behaviors work by modifying the form value on the browser side. Just like a person would with keyboard and mouse.
The edit/create/transition screen submit should take care of updating the database and index.
If you want to have changes take effect AFTER the update, you need to use a script listener instead of a behaviour. But behavious is designed to do exactly what you are describing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh wait I now see this comment from you
I only see the change in the history tab after I press the update button, not after the value is changed by the behaviour.
That is completely expected. That's what behaviour does. Changes the values on the screen and lets the user submit the change. List any other changes on the screen, nothing is reflected in the DB or index until the user actually saves the change.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan okay, that makes sense. So I need a script listener... can you point me in the right direction as to a good example to do what I need done?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will have a similar issue though.
You won't see the change in PI Review until you save the change to Closure Code.
What changes the closure code? Is this via some automation or some other external source? Or is that a user-triggered change?
If user-triggered, that I don't see why you can't keep using the current behaviour configuration.
But if you think listener is the way to do, you can find some reference in the adaptavist documentation: https://docs.adaptavist.com/sr4js/6.25.0/get-started/tutorials/listeners-tutorial
Specifically, you will want a custom listener: https://docs.adaptavist.com/sr4js/latest/features/listeners/custom-listener
And using the "Issue Updated" event, look in the changeLog for a change in the Closure Code field, and if found then make the corresponding change to the PI Review. Then save the change and force a re-index of the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehan the closure code is changed by the user. It is a form field that appears when user closes the issue. I'll review the documentation, thanks for your support!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Juan Manuel Ibarra , thanks I tried to re-index the project and it did not solve the problem. Thanks for pointing this out however
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.