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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,551,971
Community Members
 
Community Events
184
Community Groups

Set default field value to nothing

Edited

I'm looking for a way to set empty default value for select field.

I want to force the user to select an issue resolution consciously in particular project. I know about the option 'Disable defaults' on 'Resolutions' Jira administration page, but this makes resolution to have no default value for ALL projects in our Jira, when I need only single one.

The only way to acheive my goal I could think about - is to use Behaviours.

I already checked https://scriptrunner.adaptavist.com/ and merged several examples into a piece of code that changes default resolution selected in transition screen, but I couldn't find out how to completely disable default value selection or to make 'null' to be default for the Resolution field.

 

Can you help me with this?

 

P.S.: I used the following piece of code for default Resolution field value modification:

  import com.atlassian.jira.component.ComponentAccessor
  import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

  if (getAction() != null) {
    def constantsManager = ComponentAccessor.constantsManager
    def defaultValue = constantsManager.resolutions.find { it.name == 'Duplicate' }
    getFieldById(RESOLUTION).setFormValue(defaultValue.id)
  }

2 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 24, 2019

That's because the setFormValue only works with existing values.

You must first replace the available options with your own list that includes a null option and then set that null option.

Try putting this in the initializer (not on the resolution or it will reset the value each time you select it).

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

if (getAction() != null) {
def constantsManager = ComponentAccessor.constantsManager
def resolutionMap = constantsManager.resolutions.inject(["":"Select a resolution"]){map, res->
map[res.id] = res.name
map
}
def res = getFieldById(RESOLUTION)
res.setFieldOptions(resolutionMap)
res.setFormValue("")
}

Thanks a lot, it helped!

For the further readers: I modified the code a bit to avoid typecheck warnings and to make Jira check the selected value naturally, without additional validators.

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

if (getAction() != null) {
def constantsManager = ComponentAccessor.constantsManager
def Map resolutionMap = [ null: "Please select" ]

constantsManager.resolutions.inject(
resolutionMap
) {
map, resolution ->
map[resolution.id] = resolution.name
return map
}

def resolutionField = getFieldById(RESOLUTION)

resolutionField.setFieldOptions(resolutionMap)
resolutionField.setFormValue(null)
}

 

When I use 'null' as key instead of empty string, Jira sees the field has no value and produces an error if field is required.

With empty string as a key it just leaves issue with 'Unresolved' resolution and you have to add validators to the transition.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 25, 2019

Nice catch for the null vs emptyString for validations.

In the scenario where I had adapted this from is a text field converted to single select. In that case, emptyString would also fail a Field Required validation.

If you need to combine this with a transition propety to reduce the resolution set (jira.field.resolution.include) and respect it, you will'll probably end up with something like this, i.e. read and react on result of getMetaAttributes(), where the transition properties are stored:

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def action = getAction()
if (action != null && underlyingIssue?.resolution == null) {
def resolutionField = getFieldById(RESOLUTION)
if (!resolutionField) return
String resolutionIdsString = action.getMetaAttributes().get("jira.field.resolution.include")
def isResolutionSetWhitelisted = (resolutionIdsString != null)
def whitelistedResolutionIds
if (isResolutionSetWhitelisted) {
whitelistedResolutionIds = resolutionIdsString.split(",")
}
def Map resolutionMap = [ null: "" ]

ComponentAccessor.constantsManager.resolutions.inject(
resolutionMap
) {
map, resolution ->
if (!isResolutionSetWhitelisted || resolution.id in whitelistedResolutionIds) {
map[resolution.id] = resolution.name
}
return map
}

resolutionField.setFieldOptions(resolutionMap)
resolutionField.setFormValue(null)
}

 

Like # people like this

Hi @DenKoren ,

   How can we apply the same for Project field.as We want "please select a project" in project drop down while creating an issue. Thanks in advance

@Peter-Dave Sheehan  please how i can change the value of priority to character not only number ?

@Peter-Dave Sheehan 

 

This code defaults the resolution field back to 'null' regardless of the selection I have made...what am I doing wrong? 

Do not add the Resolution field to the behaviour. Instead, add the code directly to the initializer.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events