Populate description field based on a customfield dropdown list

Trang Vo May 19, 2020

Hello,

I have the following script which will fill the different texts in the description field according to the options in the custom field "Request Type". The problem is that the text in the description does not change when I change the option in the custom field. I have to click the button Create (the ticket wasn't created cause the mandatory fields are empty)/or refresh the page to have the effect.

Could you please indicate how I could have the text changed immediately when the custom field changed the value?

Thank you in advance for your help.

Here is the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager

def desc = getFieldById("description")
def selectList = getFieldByName("Request Type")

FormField Requesttype = getFieldByName("Request Type")
def stringValue = Typededemande.getValue() as String

log.error("stringValue:" + stringValue)
if (stringValue == "Access Request")
{

def defaultValue = """- Name :

- Date :

""".replaceAll(/ /, '')

desc.setFormValue(defaultValue)

}
if(stringValue == "Creation plan" || stringValue == "Creation folder"|| stringValue == "Modification Structure"|| stringValue == "Close space")

{
def defaultText = """- Name  :

- Date:

- Types :

-  Theme :

""".replaceAll(/ /, '')

if (! underlyingIssue?.description) {
desc.setFormValue(defaultText)
}}

 

1 answer

1 accepted

0 votes
Answer accepted
PD 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.
May 23, 2020

Other than perhaps what appears to be a bit of translation you forgot to adjust here:

FormField Requesttype = getFieldByName("Request Type")
def stringValue = Typededemande.getValue() as String

My guess is that you don't have this script in the correct place. In order to fire when you change the Request Type, this script must be in the Server-side Script for that field. 

Also, you can simplify your script like this:

def defaultDesc1 = """put your first default here """
def defaultDesc2 = """put your second default here """

def mapOfOption = [
[options:['Creation Plan', 'Creation Folder', 'Modification Stucture'], defaultText: defaultDesc1],
[options:['Access Request'], defaultText: defaultDesc2]
]

def desc = getFieldById("description")
def selectList = getFieldById(getFieldChanged())
def option = selectList.value

def defaultText = mapOfOption.find{option in it.options}.defaultText
if (!(underlyingIssue?.description) && defaultText) {
desc.setFormValue(defaultText)
}
Trang Vo May 27, 2020

Thank you @PD Sheehan , the script works perfectly.

Suggest an answer

Log in or Sign up to answer