Scriptrunner Behaviour updates issue immediately but time delay in filter

Pete P
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.
May 7, 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")
    (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.... 

3 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 7, 2021

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")
Pete P
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.
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.

 

dashboard1.PNGdashboard2.PNG

Pete P
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.
May 10, 2021

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

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2021

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)
0 votes
Pete P
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.
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  

Pete P
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.
May 10, 2021

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
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.
May 10, 2021

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

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2021

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.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2021

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

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 10, 2021

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.

Pete P
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.
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!  

0 votes
Juan Manuel Ibarra
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.
May 7, 2021

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