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
Community Members
Community Events
Community Groups

Scriptrunner Behaviour updates issue immediately but time delay in filter

Pete P Rising Star May 07, 2021

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

if (ClosureCodeValue=="11316") // Unsuccessful set to pending
    log.error("Unsuccessful closure code")

I am not sure which of the two methods is correct to set the value so i am using both.... 

3 answers

1 accepted

0 votes
Answer accepted

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:

Pete P Rising Star May 10, 2021

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.



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...

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



0 votes
Pete P Rising Star May 10, 2021

@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  

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

Pete P Rising Star May 10, 2021

Is there a way to force the update after changing the value in Scriptrunner?  That may do the trick

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.

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.

Pete P Rising Star May 10, 2021

@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 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:
Specifically, you will want a 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.

Pete P Rising Star May 10, 2021

@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!  

Hi Pete,

This difference may be due to an indexing issue, the changes are not reflected in searches until the ticket is reindexed.

Script runner and the java api allow forcing this re-dexation.

I give you a video where this topic is seen. Also this doc

Pete P Rising Star May 10, 2021

@Juan Manuel Ibarra , thanks I tried to re-index the project and it did not solve the problem.  Thanks for pointing this out however

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

168 views 1 6
Read article

Atlassian Community Events