Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scriptrunner for Data Center Issue Creation Select Single Field behavior help

Michael
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.
May 3, 2023

Hello,

Our organization uses a lot of required select single (Single Choice) fields (Single select drop downs) within our requests, and we are currently trying to move all of our "scripting customization" into behaviors within Scriptrunner. (We are currently using JQuery scripts within the custom fields / field configurations)

We are running into an issue with the select single (single option) fields where (by default) if the field does not have a default option selected, (which we do not want: Humans will often take the path of least resistance even if it's the wrong path) Jira adds a "None" option into the drop down.

Our end goal is to have this "None" option read as "Please select an option below", and ensure that users select a "real" option within the select single field before creating a request.

We realize that this is doable within the validators of workflows; however, we currently have the above mentioned JQuery setup on the fields themselves which is a "set once and forget" type of approach. An "add this validator to every new workflow with this field" type of solution is much more inefficient / ineffective compared to our current implementation.

Can someone please help us with a behaviors script that allows us to change the "None" value that is added by Jira (by default) to "Please select an option below"?

Thanks in advance,

~Mike

 

1 answer

Suggest an answer

Log in or Sign up to answer
2 votes
Peter-Dave Sheehan
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.
May 3, 2023

I don't think behaviour is able to change the text of the "None" option on Single Select fields.

There is a "setFieldOptions()" method that can adjust the list of available options, but it doesn't include the none/empty option. That seems to be automatically generated or added by Jira.

Judah
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.
May 4, 2023

I was going to say the same thing as Peter-Dave. I believe that you can default to whatever selection you want, but I don't think you can change the "None" option. 

You'd have to create a new option and default to that one. 

Michael
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.
May 5, 2023

Hello again,

The issue is that if we set a "Default" option, the users will tend to either:
A) Figure out that they can submit a request with the default option and hence not change it; leading to wrong information added.

B) We would need to setup a validation for that field in every workflow which is less efficient / effective than the JQuery we currently have setup on the fields themselves.

We are open to any behavioral scripting / option available which allows us to:

A) have the default option as something like "Please select an option below"
B) Validates / throws an error when a user tries to click the "Create" button within the create screen when the above default option (Please select an option below) is not changed.

Michael
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.
May 8, 2023

Hello again,

Setting the default value is a no-go considering humans tend to take the least difficult path; which would mean they'd skip over that field and leave the default value cause they can. (Basically ensuring the wrong data inside a request)

As long as we can get to the end goal of:

1) Showing a "Please select from the below" option within all Select Single fields

2) Having behaviors scripting run a validator that doesn't allow a request to be made if any Single Select fields have the "Please select from the below" option selected

We would be willing to go with any type of scripting. Is there anything you can think of that would allow us to do this?

Judah
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.
May 8, 2023

I think "None" will always have to be there, I haven't seen a way to remove it. 

As a work around, can you make the fields Required. And then script a behavior that doesn't allow a request to be made if any Single Select fields have "None" option selected? 

Michael
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.
May 8, 2023

Our current JQuery coding within the customfields themselves allows us to change the text of the "None" option into something like "Please select from the options below".

If there is a way to either include JQuery coding within behaviors scripting, or do something similar that would be ideal. Is there something like this we can implement within Behaviors scripting? (Sadly, it's starting to look more and more like behaviors isn't the "All in one" solution we thought it might be)

Thanks,

Mike

Judah
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.
May 8, 2023

Ahhh. Now that is a good question. Is there a jQuery library you can import into groovy? 

Peter-Dave Sheehan
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.
May 8, 2023

Goovy is a server-side language while jQuery is a client-side language.

The way behaviour works is 

1) A client-side request is made to the server asking if any of the fields on the currently visible form are subject to any behaviour. The request sends the list of fields and their current values. You can examine the Network calls from your browser development panel. Look for a call to rest/scriptrunner/behaviours/latest/validators.json

2) All the behaviour logic (based on any mapping that match) will be executed and 

3) The server will respond with a list of fields/actions as determined by the groovy behaviour script

4) A fixed client-side javascript logic will receive the list of actions and apply them to the correct DOM objects on the form.

5) If a server-side validator was set for any of the fields, #4 will have added the necessary event so that when you change that field, the rest/scriptrunner/behaviours/latest/runvalidator.json endpoint will be called with the selected value and the corresponding groovy script will be executed (similar to steps 3/4)

The problem is that there is no way to change the logic/capabilities that are present in the #4 step.

I think the best solution if you really want to replace the "none" entry is:

1) Set a default value in the custom field definition

2) Create a behaviour logic that will look for that default value and set an error condition on that field. This will force the user to select a different value. They will still see a "None value" in the list.

A simple script like this:

def field = getFieldByName('Single Select Example Name')
field.clearError()
def currentValue = field.value
if(!currentValue || currentValue == 'Please select an option below'){
field.setError("You must select a value")
}
Like Judah likes this
Michael
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.
May 9, 2023

Hello again Judah & Peter,

Thank you for the additional information. If this is the only work around, then it looks like we'll have to stick with JQuery due to efficency and implementation "cost".

The "None" option continuing to be present regardless, and a constant "warning something is wrong" for every Select Single field as soon as a user loads the screen is not an experience we want for our users; as it will cause confusion and annoyance.

Thanks again for all the help, and we'll keep a look out for any updates / additions that get added to the behaviors section of Scriptrunner.

~Mike

TAGS
AUG Leaders

Atlassian Community Events