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) }
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The example on your documentation page doesn't take into account the difference between newly created issues and existing issues being opened/edited.
Example:
That is the reason why i do a check if the issue is just being created or if an existing one is edited.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
flaimo
try to use the getFieldScreen() in order to determine in which screen you are.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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])
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.