Scriptrunner Behaviour: Evaluate description when user changes issue type

Based on the code sample on I have implemented template texts for whenever a user creates a new ticket and chooses "User Story" or "Bug" as an issue type.

Now there is the case where a user starts changing the description text and then realizes, that he has not yet selected the right issue type. So when he changes the issue type now, his custom description text vanishes and is replaced by the new template text. This only happens for issue types where a behaviour is defined for the description field, but not for other issue types.

Is there a way to prevent this?

def desc = getFieldById("description")
def defaultValue = """h3. IST-Verhalten
    h3. Erwartetes SOLL-Verhalten
    h3. Schritte zur Reproduktion
    # Schritt 1
    # Schritt 2""".replaceAll(/    /, '')
if (!underlyingIssue?.created && !underlyingIssue?.description) {

4 answers

1 vote
Steven Behnke Community Champion Apr 11, 2017

I have this issue too, people's descriptions are overwritten when changing the issuetype, regardless of the underlyingissue condition. It evaluates to null when you're on the create screen.

Hi flaimo,

Why the !underlyingIssue?.created condition? I mean all you need to check is if the description field has a value and if it hasn't ( that's what !underlyingIssue?.description does) then add a default one (desc.setFormValue(defaultValue))

The example on your documentation page doesn't take into account the difference between newly created issues and existing issues being opened/edited.


  1. Click "Create"
  2. Select an issue type where a behavior inserts a template text into the description field.
  3. Delete the template text in the description field so that it is empty.
  4. Save the issue
  5. Open/Edit the issue → Not OK: The description field shows the template text again, even though the user explicitly deleted the text.

That is the reason why i do a check if the issue is just being created or if an existing one is edited.


try to use the getFieldScreen() in order to determine in which screen you are. 

Thanks for the tip, but !underlyingIssue?.created actually works fine for the corner case mentioned in my comment, but I still don't know how to deal with the situation in the original posting.

Hi @flaimo,

Did you find the solution to your issues?




this is the code that we are currently using at it works fine:


import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

//set necessary component managers
def projectManager         = ComponentAccessor.getProjectManager()
def issueTypeSchemeManager = ComponentAccessor.getIssueTypeSchemeManager()

//grab current values/fields
def currentIssueType       = getFieldById("issuetype")
def desc                   = getFieldById("description")
def currentDesc            = desc.getValue()
def project                = projectManager.getProjectByCurrentKey("KSPECK")

//get all of the issue for your project
def issueType              = issueTypeSchemeManager.getIssueTypesForProject(project)

//Initialize default templates and add them to an array
def defaultValue0          = """h3. Voraussetzungen
 * OS:
 * Browser:
 * Testumgebung/Branch:

h3. Schritte zur Reproduktion
 # Schritt 1
 # Schritt 2

h3. IST-Verhalten

h3. Erwartetes SOLL-Verhalten

…""".replaceAll(/    /, '')
def defaultValue1          = """*Als _<Benutzer in der Rolle>_ benötige ich _<eine Funktionalität>_, damit ich _<den geschäftlichen Nutzen habe>._*
h3. Akzeptanzkriterien
 # (zum Beispiel Tracking-Codes, WAI-Kriterien, Mobile/Tablet/Desktop-Anforderungen)

h3. Qualitätskriterien
 * (!) Readme und Dokumentation sind aktualisiert
 * (!) Neuer Code ist getestet
 * (!) Der Styleguide (Global, Projektspezifisch) ist aktualisiert

h3. Weitere Infos

…""".replaceAll(/    /, '')
def defaultValue2          = """*Als Entwickler benötige ich _<eine Funktionalität/Eigenschaft/Technologie>_, sodass _<Ziel/Nutzen/Begründung>._*
h3. Entwicklertestkriterien
h3. Weitere Infos

…""".replaceAll(/    /, '')
def defaultValue3          = """*Als _<Benutzer in der Rolle>_ benötige ich _<eine Funktionalität>_, damit ich _<den geschäftlichen Nutzen habe>._*
h3. Akzeptanzkriterien
 * (grobe Akzeptanzkriterien von denen sich normalerweise Stories, Spikes und Tasks ableiten)

h3. Weitere Infos

h3. DoD-Checkliste (PO)
 * Gibt es ein Projekt-Ticket mit dem der Epic verlinkt werden kann?""".replaceAll(/    /, '')
def defaultValue4          = """h3. Akzeptanzkriterien
 * Welche Unklarheiten soll aus dem Weg geräumt werden?
 * Welche Aktionen sollen basierend auf dem Outcome durchgeführt werden?
 * Ist die Recherchearbeit Timeboxed?

h3. Weitere Infos

…""".replaceAll(/    /, '')
def defaultValue5          = """h3. Beschreibung

h3. Qualitätskriterien
 * (!) Readme und Dokumentation sind aktualisiert
 * (!) Neuer Code ist getestet
 * (!) (Frontend) Der Styleguide (Global, Projektspezifisch) ist aktualisiert""".replaceAll(/    /, '')
def defaultValue6          = " "
def defaultArray           = [defaultValue0, defaultValue1, defaultValue2, defaultValue3, defaultValue4, defaultValue5]

//Enter if the current description is one of the other defaults
//Or if the description field is empty
//This ensures that the description field is left unchanged if the user has already typed something
if(defaultArray.contains(currentDesc) || currentDesc == "" || currentDesc == " ")
    //Given the current issueType ID, make a decision of which default to use
        case issueType.find { == "Defect"}?.id:
        case issueType.find { == "User Story"}?.id:
        case issueType.find { == "Improvement"}?.id:
        case issueType.find { == "Dev Improvement"}?.id:
        case issueType.find { == "Epic"}?.id:
        case issueType.find { == "Spike"}?.id:
        case issueType.find { == "Technical sub-task"}?.id:

Screen Shot 2018-06-15 at 11.11.37.png 

I tried Flaimo's code to determine whether the Description field is not empty when still on the Create screen, but it's not working for me, perhaps because the goals are different. 

We are populating the typical user story format into our stories and bugs via Behaviours when users start the Create process, but if the user updates the field with their user story details and then updates the type or project, the new text is wiped out with the default user story. 

How can I get Behaviours to determine that the field is not actually null on the screen before the issue is created? 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


204 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you