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,366,256
Community Members
 
Community Events
168
Community Groups

Make field optional ONLY on create issue screen

Deleted user Oct 09, 2018

Hello everyone

I have a custom field and set it to required via field configuration for this specific issue type.

The only time it should be optional is when the issue is being created since the value cannot be set at this time.

At the moment, I have the following initialiser in my behaviour.

//Set Summary

String year = new Date().format('yyyy')

def Summary = getFieldById("summary")

if(Summary.getValue() == null)
{
Summary.setFormValue("Zinsnachzahlung " + year)
}

//Make PK-Support optional on create issue screen
if (getActionName() in ["Create Issue", "Create"])
{
def PKS = getFieldById("customfield_11904")

PKS.setRequired(false)

PKS.setReadOnly(true)
}


What this looks like.

 image.png

After clicking on create however.

image.png
Any idea on how else I could achieve this?

Thanks and best regards

Marius

1 answer

1 accepted

1 vote
Answer accepted

How about changing the custom field to optional in the field configuration for the project and keeping the code you have for the behaviour and adding a else: 

//Make PK-Support optional on create issue screen
if (getActionName() in ["Create Issue", "Create"])
{
def PKS = getFieldById("customfield_11904")

PKS.setRequired(false)

PKS.setReadOnly(true)
}else{
// will go here on any other screen that is not an edit screen (including when they edit a ticket)
PKS.setReadOnly(false)
PKS.setRequired(true)
}
Deleted user Oct 26, 2018

Clever solution! That works for me!

Thanks a lot.

(I think I'll open up a bug report for this though as this should be able to work like in my example I think)

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events