Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner - Edit Description based on Component

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)

}

1 answer

0 votes
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.
Feb 16, 2022
  1. Where is "comps" on the line "for (c in comps)" coming from?
    That variable is not defined anywhere.
  2. Suff appears to be surrounded by invalid quotes. Maybe this happened when you copied here. Or maybe this happened because you edited the script in a word processor rather than a code editor. Make sure you use either ' or " and not ” (notice the slant on the last one?
  3. You set the variable "defaultValue" to the boolean "true" if c (whatever c is ) has a name that contains stuff. Then you try to set the description to a boolean. The best-case scenario, this will be converted to a string "true" or it might fail altogether.

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 @Peter-Dave 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?

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.
Oct 19, 2023

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
Like Inayat N likes this

Thanks @Peter-Dave 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

Suggest an answer

Log in or Sign up to answer