Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Behaviour updates issue immediately but time delay in filter

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

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.

 

dashboard1.PNGdashboard2.PNG

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

piReview.setFormValue("11328")

to

piReview.setFormValue(11328L)

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

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

@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

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.

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

332 views 9 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you