Behaviours taking too long on form load?

Deleted user June 17, 2014

Hi,


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?

thanks,
Mark.

1 answer

0 votes
JamieA
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.
June 17, 2014

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?

Deleted user June 17, 2014

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?

thanks,
Mark.

// SET CLIENT BASED ON USER GROUP OF REPORTER, FOR EXTERNAL CLIENTS
// 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"))
{
  client.setReadOnly(true)
  reporter.setHidden(true)
//  reporter.setReadOnly(true)
}

if (groupManager.isUserInGroup(reporter.getFormValue(), "External Clients (CCB)"))
{
 client.setFormValue("10304")
 clientGroup.setFormValue("External Clients (CCB)")
}

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

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

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

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

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

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

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

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

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

JamieA
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.
June 17, 2014

But I will try to repro the problem.

JamieA
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.
June 17, 2014

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

Deleted user June 18, 2014

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.

Mark.

Deleted user June 18, 2014

Hi,


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?

thanks,
Mark.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events