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.
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"]
})
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.