ScriptRunner Behaviours not triggering on Create Issue screen

Raynard Rhodes
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.
January 15, 2020

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
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 15, 2020

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. 

Raynard Rhodes
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.
January 17, 2020

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"]
})
}
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 17, 2020
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.

Raynard Rhodes
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.
January 17, 2020

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