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,457,706
Community Members
 
Community Events
176
Community Groups

Scriptrunner Behaviour: Evaluate description when user changes issue type

Based on the code sample on https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html 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) {
    desc.setFormValue(defaultValue)
}

5 answers

1 vote

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!

I have this problem 

'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.'

 

But, in our case, the customer description vanish, and the fields stays empty. 

How can I fix that?

Thanks!

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? 

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

Example:

  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.

flaimo 

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?

 

Regards

Piotr

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
    switch(currentIssueType.getValue())
    {
        case issueType.find {it.name == "Defect"}?.id:
            desc.setFormValue(defaultArray[0])
            break
        case issueType.find {it.name == "User Story"}?.id:
        case issueType.find {it.name == "Improvement"}?.id:
            desc.setFormValue(defaultArray[1])
            break
        case issueType.find {it.name == "Dev Improvement"}?.id:
            desc.setFormValue(defaultArray[2])
            break
        case issueType.find {it.name == "Epic"}?.id:
            desc.setFormValue(defaultArray[3])
            break
        case issueType.find {it.name == "Spike"}?.id:
            desc.setFormValue(defaultArray[4])
            break
        case issueType.find {it.name == "Technical sub-task"}?.id:
            desc.setFormValue(defaultArray[5])
            break
        default:
            desc.setFormValue(defaultArray[6])
    }
}

Screen Shot 2018-06-15 at 11.11.37.png 

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))

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events