Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do you clear description when changing project or issuetype?

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

0 votes
Answer accepted

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

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.

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Statuspage

New feature: Slack notifications for Statuspage

We're excited to announce the release of a long-requested feature on Statuspage. Now visitors to your status page can subscribe to get notified in Slack when you report an incident or maintenance. Th...

81 views 0 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you