I use ScriptRunner and want to autofill the description field with some text - but only for issuetype "Bug".
So I followed this tutorial: https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html
But therefore I get the following problem:
- create new issue
- "Bug" was default value, so I do have the expected prefilled text in description field
- I don't want to create a "Bug", so I switch to "Task"
- description field doesn't get cleared
So I created a 2nd "Behaviour" for all issue types except "Bug":
def desc = getFieldById("description")
desc.setFormValue("")
- This cleared my description field when I change from "Bug" to "Task"
- but when I entered a usefull description and then change my mind to change issue type from "Task" to "Story", the description gets cleared again (but I want to keep it!)
So I need a condition before clearing the description field:
- clear it only if description contains the defaul text from my "Bug" behaviour
I'm not sure how to do this, especially because desc.getValue() always return "null" - regardless if it contains text or not.
Hello @Steffen Becker
You don't need two behaviours you can set the field mapping to "issueType" and everytime the issueType changes you can decide what to do with description.
Condition for checking issueType, you can use the below code in the issueType field mapping
if (issueContext.issueType.name == "Bug") { ... }
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html
def desc = getFieldById("description")
def defaultValue = """h2. How to reproduce
* step 1
* step 2
h2. Expected Result
The widget should appear
h2. Actual Result
The widget doesn't appear""".replaceAll(/ /, '')
if (!underlyingIssue?.description) {
desc.setFormValue(defaultValue)
}
Thanks for that hint, but this doesn't solve my initial problem:
a) clear description when I change from "Bug" to any other issueType
b) don't clear description when I change from any issueType except "Bug" to any other issueType except "Bug"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can check the issueTYpe and also the underlying description with the variable "
underlyingIssue?.description
And choose to clear the description or not based on the selected issueType.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help again, but that doesn't work.
I use a workaround instead:
switch (issueContext.issueType.name) {
case "Bug":
desc.setFormValue(defaultValue)
break
default:
// must be a string with length > 0 to receive the hint popup:
desc.setFormValue(" ")
break
}
This...
a) cleares description when I change from "Bug" to "Task"
b) cleares description when I change from "Task" to "Story" - but at least provides me a hint with the old value:
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.
On what field have written this behavior. I am exactly looking for the same and when I write the above behavior on description field nothing happens.
What am I missing here. Can you help me on this
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.