How do you clear description when changing project or issuetype?

Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2019

I was trying to set a default description, which I was able to do. My problem is when I change the issuetype the description is carried over. This also occurs when I change the project. I have the mapping set to a single project and single issue type. I was even trying to get past the issue with putting some validators in script that would check the issue type, but still no success. 

 

Jira v7.13.1

ScriptRunner v5.5.9 

 

def desc = getFieldById("description")

def defaultValue = """
{color:#505f79} _Complete this Story description using the following:_ {color}

*As a* <"role">

*I need*: <requirement or feature>

*So that* <goal/value>

"""

def accept = getFieldByName("Acceptance Criteria")

def acceptValue = """
{color:#505f79} _Include the Acceptance Criteria for this Story in the form of "Test Scenarios". If the criteria is documented elsewhere, provide the link._{color}

Test Scenario:

Test Scenario:

"""

if ((getActionName() == "Create") && (issueContext.issueType.name =="Story")) {
desc.setFormValue(defaultValue)
accept.setFormValue(acceptValue)
}

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2019

The way to avoid this is to make your mapping global (all issue type and all projects).

Then detect in your script what the project and issue types are.

If you have a need to have different defaults for different project/issuetype, you will need to account for that in your script. For example:

def mapping = [
PKEY1 : [
Story : [
desc: "default Story description for project PKEY1",
accept: "default Story acceptance criteria for PKEY1"
],
Task : [
desc: "default Task description for project PKEY1"
]
],
KEY2 : [ /*other defaults here for KEY2 projects*/]
]

if (getActionName() == "Create"){
def proj = issueContext.projectObject
def issueType = issueContext.issueType
def acceptFld= getFieldByName("Acceptance Criteria")
def descFld = getFieldById('description')

def defaults = mapping[proj.key][issueType.name]

if(defaults?.desc){
descFld.setFormValue(defaults.desc)
} else {
descFld.setFormValue("")
}
if(defaults?.accept){
acceptFld.setFormValue(defaults.accept)
} else {
acceptFld.setFormValue("")
}
}
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2019

One warning I should add...

The default jira behavior (when you don't use Scriptunner behavior to set form values) is to keep the text typed by the user when they change project /issue type.

So with a script like what I suggested, you could end up wiping out user's entry if they decide they want to change issue type (e.g. when changing between 2 issue types of a project without defaults).

One possible workaround is before setting the value to "" is to compare the value with all default options from all projects and issue types, and only set the form to "" if the form currently contains a known default.

The minute the user makes a change to the text, they own that text and changing type or project won't re-set the default value.

Another approach (untested) is to modify the field description dynamically with scriptrunner behavior and include a link that the user can click to re-set the field to the default. But you will have to populate that description with some javascript to replace the text. no small feat.

Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2019

Thanks so much. Still some work to be done on the script, but yea the mapping was the main issue.

Thierry Dalon
Contributor
June 22, 2022

Could you provide the code that implement the workaround please?

TAGS
AUG Leaders

Atlassian Community Events