It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Behaviours not triggering on Create Issue screen

Hello,

I have scripted fields to display values based on the value of another field. This works fine if I have an already created issue, but when I create a new issue there is not action/change to the fields. I've placed the exact same code in the 3 fields and initialiser. 

Is there specific code I need to use in order for this to function on the create screen? Am I only to place the code in the initialiser field?

 

Any help would be appreciated.

1 answer

1 accepted

1 vote
Answer accepted

You should only need to have your script on the field that actually triggers the change. Unless you want some default values to be applied before the user makes any selection. Then that would have to be in the initialiser.

But perhaps there is something that your script does in terms of looking up values that uses an issue object. That issue object won't exist yet in the create context. 

Below is the code (the rest is just repeating the if statements for other values)

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FormField

@BaseScript FieldBehaviours fieldBehaviours

def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

FormField lob = getFieldByName("LOB: ")
FormField lobPrograms = getFieldByName("LOB:Programs ")
FormField lobProject = getFieldByName("LOB:Project ")


def lobPrograms2 = customFieldManager.getCustomFieldObjectByName("LOB:Programs ")
def lobProject2 = customFieldManager.getCustomFieldObjectByName("LOB:Project ")
def lob2 = customFieldManager.getCustomFieldObjectByName("LOB: ")

def lobProgramsValue = lobPrograms.getValue()
def lobValue = lob.getValue()

def fieldConfig = lobPrograms2.getRelevantConfig(issue)
def fieldConfig2 = lobProject2.getRelevantConfig(getIssueContext())
def fieldConfig3 = lob2.getRelevantConfig(issue)


def getOptions = optionsManager.getOptions(fieldConfig)
def getOptions2 = optionsManager.getOptions(fieldConfig2)
def getOptions3 = optionsManager.getOptions(fieldConfig3)


if(lobProgramsValue=="CBB"){
lob.setFieldOptions(getOptions.findAll{
it.value in ["CBB"]
})
lobProject.setFieldOptions(getOptions2.findAll{
it.value in ["cbb-research"]
})}
//Grouped below for conditional LOB: Program relation with LOB: Project
if(lobProgramsValue=="CTG"){
lob.setFieldOptions(getOptions3.findAll{
it.value in ["-C direct-", "CDD", "ClinVar"]
})
lobProject.setFieldOptions(getOptions2.findAll{
it.value in ["Unknown/TBD"]
})
}
if(lobValue=="-C direct-"){
lobProject.setFieldOptions(getOptions2.findAll{
it.value in ["clinical-trials","ctg-data"]
})
}
def fieldConfig = lobPrograms2.getRelevantConfig(issue)
def fieldConfig2 = lobProject2.getRelevantConfig(getIssueContext())
def fieldConfig3 = lob2.getRelevantConfig(issue)

These fiedConfig and fieldCongfig3 will fail on create screen. Buf fieldConfig2 will be fine.

This means that getOptions and getOptions3 will also be bad etc.

Try to use issueContext instead of issue for all 3.

Thank you so much. Funnily enough I used "issue" and "getIssueContext()" to see if there was a difference between the two. fieldConfig2 is actually the only one that doesn't affect another field, so I would've never known. Again thank you!

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you