How to prevent Behaviour script from running when the page first load?

THOMAS SEBASTIAN August 26, 2015

Is there a way to prevent the Behaviour/groovy script from running when the Edit screen first pop up?  We have a requirement where the behaviour script should only be invoked when user is clicking the field where the script is attached to, not from the beginning like how the default behaviour of script runner is.  This is to prevent the script from overwriting the content of a custom field which is imported through CSV as we want to keep the legacy value as it is.

Thanks in advance.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
GabrielleJ
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.
August 27, 2015

You will have to code that. A javascript in the page that listens on the field ID of your custom field. The script runner as you have said, has a default behaviour of doing it everytime it is brought up. The javascript can be inserted in multiple places, most of the people put in the Custom Field Description (https://confluence.atlassian.com/jira/fields-allowing-custom-html-or-javascript-224401453.html). Some of them put it in the JIRA Header. Your preference.

THOMAS SEBASTIAN August 27, 2015

Hi Gabrielle, do you know which event that is triggered every time the Edit screen brought up? And do you know what code that triggers the behaviour script to run? I tried to find this but have been unsuccessful so far.

GabrielleJ
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.
August 28, 2015

Why do you need the event of the Edit Screen? If you wish to place it on the edit screen, try putting it in a Custom Field Description. We always want to avoid updating a system file (like the Edit Screen file) due to a couple of reasons.

THOMAS SEBASTIAN August 30, 2015

Oh what I meant is which event that was called when the Edit screen is popping up? Because I will need this to do the coding as you suggested above. Basically what I'm trying to achieve is for the script runner NOT to run the first time the Edit screen is brought up; only when the user change the selection of the custom field. So now I need either one of these two: 1.) The code that will ONLY be invoked when a user make a selection. 2.) Or a code that will prevent the script runner from running when the screen is brought up for the first time. Thanks for the help.

GabrielleJ
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.
August 31, 2015

1.) You should just not use it and let the javascript do all your work which is in the custom field's description. Not sure what is the name of the file for the "EDIT" screen because I don't want to mess with system stuff like this.

TAGS
AUG Leaders

Atlassian Community Events