Can someone review and let me know why this wont work?
import com.atlassian.jira.bc.project.component.ProjectComponent
def desc = getFieldById("description")
def component = getFieldById(getFieldChanged())
def defaultValue = """
*WHAT:* chicken, chicken chicken
*WHY*
""".replaceAll(/ /, '')
for(c in comps){
if(c.getName().contains(“Stuff”)){defaultValue = true}
}
if (! underlyingIssue?.description) {
desc.setFormValue(defaultValue)
}
Perhaps the following will achieve something close to what you expect:
import com.atlassian.jira.bc.project.component.ProjectComponent
def defaultValue = """
*WHAT:* chicken, chicken chicken
*WHY*
""".stripIndent()
if (! underlyingIssue?.description) {
def components = getFieldById(fieldChanged) as List<ProjectComponent>
if(components.any{it.name.contains('Stuff')}){
def desc = getFieldById("description")
desc.setFormValue(defaultValue)
}
}
Hi @PD Sheehan . I tried this code. It compiles with no issues, but it does not seem to populate the Description. In the behavior, I have it set to the Component/s field, not the initializer.
If the component of 'Stuff' is selected on the create screen, it should add the defaultValue to the description box, right?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Correct, that's what this code is designed to do.
If that's not working for you ( and you are on a server/dc instance) you will need to add some logging and review your jira logs to see what might be happening.
For example:
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.apache.log4j.Level
log.setLevel(Level.INFO) // make sure log level is adequate to view the messages
log.info "Start of behaviour for Component/s field"
def defaultValue = """
*WHAT:* chicken, chicken chicken
*WHY*
""".stripIndent()
if (! underlyingIssue?.description) {
def components = getFieldById(fieldChanged).value as List<ProjectComponent> //I see the original code was missing .value
log.info "component/s field contains ${components.size()} values, checking if any of them contain stuff"
if(components.any{log.info("component name=$it.name");it.name.contains('Stuff')}){
log.info "stuff component found, setting the description field"
def desc = getFieldById("description")
desc.setFormValue(defaultValue)
}
} else {
log.info "an existing issue was detected ($underlyingIssue.key), we won't update the description"
}
log.info "end of behaviour for Component/s field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @PD Sheehan . This is working now. I did have to make one correction and change:
import com.apache.log4j.Level
to
import org.apache.log4j.Level
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.