I have been experimenting with the Behaviours plugin in JIRA.
I have been successful with many scripts, but I am not able to figure this one out. I want to be able to insert text into a custom text field, if a certain selection is chosen from a select field.
Here is my code:
import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.*
// Get pointers to the custom field(s) required
def cf = getFieldByName("Custom Select list field A")
def cf1 = getFieldByName("Custom text field B")
// Get the Value of Custom Field A
def cfVal = cf.getValue().toString()
if (getActionName() != "Create Issue") {
return // not the initial action, so don't set default values
}
if (cfVal == "Selection from Select List"){
cf1.setFormValue("Default text I want to have input")
}
I was attempting to follow https://scriptrunner.adaptavist.com/4.3.0/jira/recipes/behaviours/setting-default-fields.html as closely as possible, but can't seem to get it to work.
Any help is greatly appreciated!
-Nick
Hi Nick,
I have attached a sample script below which shows how you can add some default text to a multi line text field when a certain option is selected in a text field and remove the text once the option in the select list field is changed.
// Get pointers to my fields def textField = getFieldByName("DemoTextFieldMultiLine") def selectList = getFieldByName("DemoSelectList") // Get the Value of my Select Field def selectListVal = selectList.getValue() // Specify my default text String defaultText = "This my default text to add to my multi line text field." // If the Select List Value matches the option A then set some default Text if(selectListVal.toString() == "A"){ textField.setFormValue(defaultText) }else{ // If the select Field value is unselected or a different match then clear the default text textField.setFormValue("") }
Also if you want to restrict this behaviour to only apply on the create or edit screens then you can do this by Simply adding the workflow used as a Guided Workflow to your behaviours and add a condition to specify when this behaviour should fire.
I have attached a screenshot below which shows how to restrict this behaviour to the edit screen but this could easily be modified to only allow the behaviour to fire on the create screen.
Screen Shot 2016-10-05 at 12.01.38.png
I hope this helps.
Thanks
Kristian
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.