Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,866
Community Members
 
Community Events
165
Community Groups

Behaviour to exclude None field value from custom select list doesn't work for inline editing

Edited

We use Jira Data Center with ScriptRunner, and have a need to remove the “None” option from one of our custom select list fields.

I have already looked at a few discussion threads, and based on them, here are the steps I took:

  1. Added a new value (in Jira field configuration) called Undefined and set it as the default to use instead of None
  2. Created a new behaviour, and:
    • Added the following code to the initializer
    • Added the same code below to the server side script
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import org.apache.log4j.Logger

// Grab appropriate managers
def cfManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

// Grab form and custom field values
def selectCF = cfManager.getCustomFieldObject("customfield_11616")

def selectField = getFieldById ("customfield_11616")

// Must grab the relevant config given the current issue context and the custom field
def config = selectCF.getRelevantConfig(getIssueContext())

// Given config, grab a map of the possible options for the select custom field
def options = optionsManager.getOptions(config)
selectField.setFieldOptions(options.collectEntries{[(it.optionId): it.value]})

This seems to work for Create Issue and Edit Issue screens and the None option is indeed removed from the list of choices. However, when I try to do inline edit on the field, the None option is still there.

 

I'm hoping someone can chime in and tell me what I am doing wrong here.

I'd greatly appreciate any help I can find.

Many thanks,

Kamran 

1 answer

1 accepted

0 votes
Answer accepted

The way behaviours are implemented, they don't work for inline edits.

Normally, when you apply a behaviour for a field, scriptrunner disables the inline edit and any attempt at editing in-line will open up the edit screen.

But maybe this automatic disabling of inline edit only works if you have a setReadOnly or setRequired.

You could try to manually disable the inline edit by adding:

selectField.allowInlineEdit(false)

Thank you so much for your reply!

It's disappointing to know that behaviours don't work with inline edits :/

I would be satisfied with the the edit screen opening up when the user attempted inline editing, and updated my code with what you suggested. Unfortunately, even this behaviour (no pun intended) is inconsistent at best. In my case, the inline edit works (without the edit screen opening up) only 2 out of 5 times.

If you have any other suggestions, I'd love to hear them. Regardless, your help is much appreciated!

All behaviour functionality relies heavily on client-side javascript functionality. So there are some inherent limitations that this comes with. 

Including having possible delays before the client-side applies the DOM change associated with the desired behaviour (which first has to be fetched from the server-side script).

So if your browser or PC is busy or the user very fast, the DOM changes may not have been applied yet.

Can you give your screen a 3/5 second delay to see if you still see inconsistent behaviour? I can't think of what else would cause the intermittent results.

The other option is to make this field required at the field configuration level. This way, while "none" will be visible in the list, user won't be able to select it without tripping the required field validation.

Thank you for all your help thus far!

You were right that the DOM changes were slow to apply. However, in the end, we decided to can the implementation altogether because I was still able to edit the field inline by getting to it through the global shortcut ("." key or "gg"), and that wasn't acceptable for what we were trying to accomplish.

I appreciate your help!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

310 views 0 9
Join discussion

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