Forums

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

Scriptrunner - Script to show questions depending on previous questions

Daniel Drysdale _UK_ April 8, 2019

Hi, 

I am trying to run a simple script on the jira issue create screen. I am struggling with how to deploy it. 


I have a question and if you answer yes it should display a further 3 questions. If you answer no none of these questions should display.

I believe a script similar to this one i found on the forum should work but i am just unsure of where to add a listener or how to actually execute.

def select = getCustomFieldValue("Select")
if (select) {
return select
}
else {
return null
}

Many thanks for you help 

 

1 answer

0 votes
Tansu Akdeniz
Community Champion
April 8, 2019

Hi @Daniel Drysdale _UK_ ,

Welcome to community.

In order to do that, you should use Script Runner's Behaviours feature.

Go to;

  • Add-on -> Behaviours
  • Add new behaviour
  • Than add mapping to this behaviour (project / issuetype)
  • Than click the Fields button

Than, add your field (your question field). And add server side script for this field.

Here is an example;

def questionField = getFieldById(getFieldChanged())
def questionVal = questionField.getValue() as String

def otherField = getFieldById("customfield_XXXXX")

if(questionVal.equals("No")) {
otherField.setHidden(true)
otherField.setRequired(false)
} else{
otherField.setHidden(false)
otherField.setRequired(true)
}

ps: It works in Create & Edit dialogs unless you specify a condition.

Regards

Daniel Drysdale _UK_ April 8, 2019

Hey thanks for you reply, I cant seem to see an option for behavious under add-on for some reason?

Tansu Akdeniz
Community Champion
April 8, 2019

I couldn't understand the problem, can you please share a screenshot? 

*You can also click "." button on keyboard and type "Behaviours" on pop-up.

Daniel Drysdale _UK_ April 8, 2019

screenshot_jira.png

Daniel Drysdale _UK_ April 8, 2019

clicking "." brings up nothing either 

Tansu Akdeniz
Community Champion
April 8, 2019

You are using cloud version, got it. 

As I know, only server version supports Behaviours feature because of some limitations in cloud.

Daniel Drysdale _UK_ April 8, 2019

Okay i thought it would be something like that thank you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events