How to create default template using "Initialisers" in Script Runner add-on?

I have got question about "Initialisers" feature in Script Runner add-on.

I want to have a default value/template in one project for the Description field, but keep it empty for the rest of projects. But when I click on "Create" button, a template appears and later I change the project from drop-down list, the template is not cleaned up.
It's working but, but only when I create explicitly rule ("empty template") for the rest projects.
Every time, when new project is created, I need to remember about that. Isn't any better solution for that?

Thank you in advance for help!

Michal

 

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

2 answers

1 accepted

1 vote

It can't really know what it's done, in order to undo it all when you change projects. The user may have made further edits and would not expect it to be wiped out.

In my experience, most end-users, most of the time, generally create issues in one project.

Ok, thank you for the answer.

Hi @Jamie Echlin [Adaptavist],

Is it possible to templatize a custom field and use "underlyingIssue" to check if the custom field is empty?

I have used the code above to create a standard template for the Description field and it works great, but can't seem to figure out how to do the same for a custom field.

For example:

def cf = getFieldById("customfield_10013")
def defaultValue = """Blah blah blah
    """.replaceAll(/    /, '')
if (! underlyingIssue?.(CustomField "customfield_10013")) {
cf.setFormValue(defaultValue)
}

Thanks in advance for your support,

Terry

Yes, but use CustomFieldManager to get the CF value from the issue. 

Hi @Jamie Echlin (Adaptavist), please forgive my ignorance on this as I am not a developer, so still having some issues with getting the script to work for a custom field.

I have added the following and tried a few different things with underlyingIssue to check if the custom field is populated, but still can't get it to work.  :|

import com.atlassian.jira.issue.CustomFieldManager
def cf = getCustomFieldValue("customfield_10013")

Any additional help would be gratefully appreciated.

Thanks for your support,

Terry

Hi @Jamie Echlin (Adaptavist), just wanted to check back with you to see if you had any additional input on how to resolve this issue with templatizing a custom field as the few things I tried did not work.

Thanks for your support,

Terry

@Terry Beavers, Try This:

import com.atlassian.jira.issue.CustomFieldManager
def cf = getFieldById("customfield_10013")
def defaultValue = """Blah blah blah
    """.replaceAll(/    /, '')
if (! underlyingIssue?.description) {
cf.setFormValue(defaultValue)
}

Apparently ".description" just pulls the value of the custom field. I think they could have avoided some confusion if the example they used wasn't the "Description" field.

That did the trick!  Thank you @Andres Fuentes!

import com.atlassian.jira.issue.CustomFieldManager
def cf = getFieldByName("Steps to Reproduce")
def defaultValue = """*+Steps to Reproduce+*
*+Actual Results+*
*+Expected Results+*
    """.replaceAll(/    /, '')
if (! underlyingIssue?.description) {
cf.setFormValue(defaultValue)
}

I do have another odd scenario I discovered while testing though that hopefully you can shed some light as well.

This particular behaviour script is configured to execute against the following two issue types, Bug and Hot Fix.

The problem I have encountered is if the user enters data in the Steps to Reproduce field, but then changes the issue type to the other issue type that is supported with the script, the current data in the field is wiped out and replaced with a new Steps to Reproduce template.

For example, I go to create a new issue as a Bug and populate the Steps to Reproduce field with some additional data using the template.  I then change the issue type to Hot Fix before submitting the ticket and the data in the field is wiped out and replaced with a new Steps to Reproduce template.

On the other hand, if I go to create a new issue as a Bug and populate the field with some additional data using the template and then change the issue type to Improvement before submitting the ticket, the data remains in tact as expected, but if I then change the issue type back to Bug or Hot Fix before submitting the ticket, the data in the field is wiped out and replaced with a new Steps to Reproduce template.

It seems like the script is reinitializing when the issue type is changed to a supported issue type, but only during create, not during edit.

Any thoughts, ideas or suggestions?

JIRA version is 7.0.10 and ScriptRunner version is 4.3.5

Thanks for your support!

Just replying with some initial thoughts... I have yet to investigate this. 

So in researching this last week I found some people were talking about this an issue similar to what you're mentioning. I think you may have to add some additional logic.

Something like:

if (!underlyingIssue?.created && !underlyingIssue?.description) {
    desc.setFormValue(defaultValue)
}

This would verify that the issue is being created and not moved.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,316 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot