Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I dynamically populate Description in the Create Screen based on a Custom Field FormField?

Jordan Klein April 18, 2018

I have a Single Select List Custom Field called "Test Request Type" Options include Level, Character, and Weapon.

When Creating a "Test Request" issue type (on the Create screen), I would like to dynamically change the Description field based on the user's form selection of the Test Request Type field.

To accomplish this, I have tried using Scriptrunner Behaviors. 

The code block below is a serverside script attached to the Test Request Type field, but I can't get the Description field to update dynamically based on the user's choice.

Any help would be appreciated! 

 

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

FormField testRequestType = getFieldByName("Test Request Type")
def stringValue = testRequestType.getValue() as String

if (stringValue == "Level")
{
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(/ /, '')

desc.setFormValue(defaultValue)

}


 

2 answers

0 votes
JohnsonHoward
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.
April 19, 2018

Hi Jordan,

 

What does the behaviour configuration screen look like? and what version of JIRA and SR are you using?

 

I have just recreated the environment you described and use the exact same code and got the below result. This makes me believe it is something in the configuration of the behaviour.

Screen Shot 2018-04-19 at 09.45.19.png

0 votes
Alexey Matveev
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.
April 18, 2018

What is the error? Did you add the Test request type to the behaviour and add the script to the field? Kindly log info into logs and see the logs

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

FormField testRequestType = getFieldByName("Test Request Type")
def stringValue = testRequestType.getValue() as String

log.error("stringValue:" + stringValue)
if (stringValue == "Level")
{
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(/ /, '')

desc.setFormValue(defaultValue)

}

Suggest an answer

Log in or Sign up to answer