Scriptrunner behavior default text and validation error resets field completely

We are using the scriptrunner behavior plugin to set the default text of the description (so that the user has a template to fill out) when opening the create issue screen. Everything works as expected, however an issue we are facing is the scenario when a validation error occurs when clicking "Create" in the dialog.

The validation error gets displayed however the description is set to the default text again, losing all previously entered information.

The code we are using is the following:

import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.*

if (getActionName() != "Create Issue") {
    return 
}

def desc = getFieldById("description")

def defaultValue = "SOME DEFAULT VALUE''

desc.setFormValue(defaultValue)

1 answer

1 accepted

Are you using an Initializer function? If you are, I would instead create a behavior directly on the Description field with a script similar to this:

def desc = getFieldById("description")

def defaultValue="Your Default"

if(!desc.getValue())
{
    desc.setFormValue(defaultValue)
}

Thanks for the answer, but how do I create a behavior directly on the description field?

I tried this by "Adding" the description field to the behavior and then adding a server side script with the snippet you provided. However this does unfortuantly not work.

Ok, I figured it out. I forgot to set a condition when this script should be run.

Thanks!

How did you do it? I have same situation..

I added a condition that the script should only be run when the workflow step is "Create issue" (the first workflow step in my workflow).

Is your validation in the behaviors plugin or in the field configuration? It still did not work for me. I still get my fields reset when validatioin fails during create issue (e.g. missing component, required in field configuration)

Behaviours

  • Add behaviour (name it)
  • Click "Fields" in newly created behaviour
  • Select your Guide Workflow
  • Add the description field to the relevant fields
  • Add the server side script
  • def desc = getFieldById("description")
    
    def defaultValue = "SOME TEXT HERE"
    
    if (!desc.getValue()) { 
        desc.setFormValue(defaultValue)
    }
  • add condition:
    • when "workflow action" - select your action

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

168 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you