Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Autofill description field only for specific issue types

Steffen Becker
Contributor
January 11, 2019

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.

1 answer

1 vote
Tarun Sapra
Community Champion
January 11, 2019

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

https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/conditional-based-on-issuetype-and-project.html

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

 

Steffen Becker
Contributor
January 11, 2019

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"

Tarun Sapra
Community Champion
January 11, 2019

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.

Steffen Becker
Contributor
January 14, 2019

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:

hint.PNG

Like Tarun Sapra likes this
Tarun Sapra
Community Champion
January 14, 2019

Glad to know @Steffen Becker that it's working now!

Vineela Durbha
Contributor
August 25, 2020

@Steffen Becker 

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 thisdesc.PNG

Suggest an answer

Log in or Sign up to answer