Behaviours taking too long on form load?


I've got a behaviours script running off "reporter" which works great, but the problem is that if you click on a field (e.g. Issue type) too quickly then the script doesn't seem to get a chance to run and it sets a field value to the default, rather than the value that should be determined by the script.

It feels like the script is taking a while to load/run and you can therefore manage to bypass it if you're quick enough.

Is there a way to chnage the way the script loads, or deactivate the form until it has? Or any other advice around this?


1 answer

How long does it take? You should be able to see from looking at the network tab on F12 tools in your browser.

Is the behaviour applied to all projects, or at the least the one they are changing to?

IIRC when you change projects it should clear all behaviours and reload the ones for the new project / issue type.

What does the behaviour do in your case?

What's the version of jira and the plugin?

Hi Jamie,

Thanks for your quick response. we're on jira 6.1.6 and behaviours 0.5.10

Screenshot attached showing load times, and code is below.

The behaviour is enabled for one project (but all issue types), and should set two fields (based on reporter) i) Client ii) Client Visibility.

If you're really quick you can change issuetype (not project) and client visibilty is set as the default "jira-users" rather than the correct value. this isn't reproducible if you give the form time to load, long pauses between changin issue types, etc.

Any thoughts?


// Mark Love, 18th June 2014
// This script pre-populates the "Client" and "Client Visibility" fields, based on whether the reporter belongs in a particular user group
// It assumes that all external client users are a member of i) "External Clients" and ii) "External Clients (Client ABC)"
// This script will need updating for each new client that requires access to the Ops project
// This script will only work for issues raised directly in Jira, since the Behaviours plug in does not apply to Service Desk

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager

def groupManager = ComponentAccessor.getGroupManager()

// Get the name of the current user (not the reporter, since this will be different for internal ops users logging jobs for others)
def user = ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName()

FormField client = getFieldByName("Client")
FormField reporter = getFieldById("reporter")
FormField clientGroup = getFieldByName("Client Visibility")

// Disable the "Reporter" and "Client" fields for all external users (only)
if (groupManager.isUserInGroup(user, "External Clients"))
//  reporter.setReadOnly(true)

if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (CCB)"))
 clientGroup.setFormValue("External Clients (CCB)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Masthaven)"))
 clientGroup.setFormValue("External Clients (Masthaven)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Paratus)"))
 clientGroup.setFormValue("External Clients (Paratus)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (M2L)"))
 clientGroup.setFormValue("External Clients (M2L)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Hampshire Trust)"))
 clientGroup.setFormValue("External Clients (Hampshire Trust)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Pepper)"))
 clientGroup.setFormValue("External Clients (Pepper)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Zebra)"))
 clientGroup.setFormValue("External Clients (Zebra)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (KRBS)"))
 clientGroup.setFormValue("External Clients (KRBS)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Titlestone)"))
 clientGroup.setFormValue("External Clients (Titlestone)")

else if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (Pure)"))
 clientGroup.setFormValue("External Clients (Pure)")

But I will try to repro the problem.

The screen shot is not there, but no matter.

This probably seems like a cop out on my part, but this kind of timing issue is going to be tricky to debug, and, I think this is a bad use of behaviours. I'd use this if you wanted to default a field based on the user group and allow the user to then change it, but I think you are setting it and hiding it. That being the case, it's simpler and safer to use a post-function. The code would be very similar (a groovy script post-function).

Hi Jamie,

No, it's not a cop-out. I work in IT, so I appreciate how difficult it can be to reproduce or resolve issues like this.

I considered a post-function, but I wanted the user to be able to see the values that were defaulting on the screen. Also, one of the fields is mandatory, and I want internal users to be forced to set it (the script only applies to external users) so if I make it non-mandatory and use a post-function (for external users) it may not always get populated.

Thinking as I type, perphaps I should use a behaviour to make it mandatory for internal users, hide the fields from external users, and then put everything else on the post function.



To run a groovy script as a post function do I need to place a file with the script on the server using the "Script Post-Function"? And, if so, where do I place the script?

This is going to make it very difficult for me to edit and test the script - is there no way to have a scripted post-function through the UI?


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

465 views 8 27
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you