How to add Default text in Description using script runner behaviours

Bunty April 25, 2019

Hello All,

I have set default text in Description field by adding below script in the behaviour intialiser. I have added mapping to one project and only one issue type:

def desc = getFieldById("description")
   
def defaultValue = """Example Text """
if (getActionName() == "Create"){
      desc.setFormValue(defaultValue)
}
else {
    
    }

It is working fine but when i selecting other issue types in the same create screen it is populating the default text in all issues. I want to populate the default text only for one issue type.

Any help?

Thanks in advance,

Bunty

2 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 26, 2019

Actually, @Fabio Racobaldo _Herzum_ setting the mapping will not clear the default text.

Think of manual changes, if you type some description, then change issue type, the text you typed will still be present in the form.

Your second option, or leaving all issue type mapped and clearing or entering the default text based on the issue.

I think the issue manager is not needed in this case. You already have the issueContext in the binding. Plus, at creation, there is no underlyingIssue during the create step.

You can get the issue type with issueContext.issueType.name 

@Bunty we have several projects that have a default description just for one issue type. I simply accept the fact that users will have to clear/replace the default description. That's never been an issue.

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 26, 2019

Hi @Bunty ,

you have two options to do that :

  • Define a specific mapping for your behaviour selecting just your issue type
  • image.png
  • Add a check based on issue type on your script. Retrieve issue type name and add a check on name on your script
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;

IssueManager im = ComponentAccessor.getIssueManager();
Issue i = im.getIssueByCurrentKey(underlyingIssue.key);
def issuetypename = i.getIssueType().getName();
...
YOUR CODE
...

The first one is immediate.

Ciao,

Fabio 

Suggest an answer

Log in or Sign up to answer