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 behaviours not honoring Required for my "select list" on my service desk

Has anyone else run into this problem?

  • I've got a request type in a Jira Service Desk with a Project select list that I want to be optional by default (so it can receive email) but when a user is using the service desk portal, I want the Project select list to be required.
  • I set up ScriptRunner Behaviours to make the Project select list required on the service desk portal.  I know it's configured correctly because the "(optional)" note is gone from the field since I set up the Behaviour.  However, I can still submit a ticket without selecting something in the Project list (by leaving it as "none").

The only thing I can think is that Behaviours is seeing the "none" option selected in the Project select list as a viable option, instead of not one of the real options at all.

Note: "none" is not one of the options configured for the select list.  It's only showing up because we don't want to set a default value for this particular select list so Jira puts a "none" in the select list for you when the form first loads.

2 answers

1 accepted

1 vote
Answer accepted
Mark Markov Community Leader Jun 06, 2018

Hello, @Crystal Gummo

Actually, there is a workaround for this problem.

You can control field input by setErrror(), clearError() methods.

Just add add behaviour to the target field, and here script example:

Boolean isValid
if (!StringUtils.isEmpty(getFieldById(getFieldChanged()).getValue())) isValid = true
isValid? getFieldById(getFieldChanged()).clearError() : getFieldById(getFieldChanged()).setError("You must enter field value")

I really like this idea. 

I got an error when I tried your code:

StringUtils is undeclared.

so I added a 

import org.apache.commons.lang3.StringUtils;

And then got this error:

Screen Shot 2018-06-06 at 10.46.53 AM.png

it seems to be an error between types (object vs string). But I tried a few different things and couldn't get it to resolve.

So, I tried to write something similar, but while this doesn't give an syntax error, it still lets a user submit a ticket with "None" selected in the dropdown:

def ProjectFieldValue = getCustomFieldValue("12515")
Boolean isValid = true

if (ProjectFieldValue.equals("None")) isValid = false

isValid? getFieldById("12515").clearError() : getFieldById("12515").setError("You must enter a Project")

Any ideas where to go from here?

Mark Markov Community Leader Jun 06, 2018

@Crystal Gummo 

Your method does not work, because it gives you the NullPointerExeption (ProjectFieldValue is null)
Static type checking in not important, in runtime groovy will cast types anyway.
If it bothers you too much you can just cast it as String

Try the code bellow, it should work

import org.apache.commons.lang3.StringUtils
Boolean isValid = false
if (!StringUtils.isEmpty((String) getFieldById(getFieldChanged()).getValue())) isValid = true
isValid? getFieldById(getFieldChanged()).clearError() : getFieldById(getFieldChanged()).setError("You must enter field value")

You rock!

It works like a charm, with just one drawback:  The field in question starts off red with the error message, as soon as the user pulls up the form.  It's kind of like yelling at them when they haven't had the opportunity to mess up yet.  Any ideas on how to avoid that?  I admit I can't think of anything and this solutions as-is is already so much better than what I had before.

Mark Markov Community Leader Jun 06, 2018

A behaviour works as soon as a form loads,  so it's imposible to postpone that moment with behavior.
If you want to check fields after the submit button was pressed, you can use the simple scripted validator on the create transition with a condition like this:

cfValues['project_field1']?.value != null 

but the field will be required everywhere on issue create.

One more variation. Service desk has the "Customer Request Type" field , the value for the field is set only if an issue is created from the portal or email (via service desk handler). So you could try a validator like this:

cfValues['project_field1']?.value != null && cfValues['Customer Request Type'] != null

 So if you have service desk mail handlers configured, you need to test this solution, if it affects issue creation via email.

Thanks!  I've already marked your solution as the "accepted solution" because it was so much better than just living with the problem until the underlying bug is resolved.

I've already got your setErrror/clearError approach in place on our production system and people are happy.

Thanks again!

We are currently aware of bug SRJIRA-2810 which causes the system to consider "None" as a valid option when it shouldn't be.

Thanks, I'll start watching that ticket and close out this conversation. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Managing Incidents - The roof is on FIRE!

The roof is on FIRE… network outages, broken processes, upset clients and employees. Each day seemed to bring more and more issues. Incidents were communicated via email, messengers (skype or teams) ...

119 views 0 1
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