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

Resolving a 400 Bad Request error on a Script Listener

Hi Jira gurus!  

After many searches, I am reaching out to the community for a little help on this one.  I am using this ScriptListener to update the story points from all issues in an Epic to the Epic parent.  

The listener is working except for its main purpose - updating the field!  Every attempt I make to fix this results in an error.   Any suggestions are much appreciated. 

The original script is here and I have modified it for IssueType to include Bugs, Tech Debt, Hot Fixes, etc. 

https://bitbucket.org/snippets/Adaptavist/rAGj67?_ga=2.203170839.722525303.1572858588-255267661.1554209298

Screen Shot 2019-11-05 at 1.47.39 PM.png

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 05, 2019

Hi @Davey ,

From the error log I could see that you've framed your jql query in script with syntax error

Can you paste your jql part in script to take a look

 

BR,

Leo

Thanks @Leo !  

Pasting the script since it is a small one.   From what I can tell the jql is where this comment starts - // Note: The search API is limited that to only be able to return a maximum of 50 results

/*
* This script listiner which should be configured on the issue updated event and shows how you can update the value of the story points field on the epic to show a sum of the values from the story points field for all stories linked to the epic, each time the epic issue is updated.
* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
* or amended and must be included in any circumstances where the code snippet is shared by You or a third party."
*/

if(issue.fields.issuetype.name.toString() == "Epic"){

// Get the Epic Issue Key
def epicIssueKey = issue.key.toString()
logger.info("Epic Key = " + epicIssueKey)

// Get the field ids
def fields = get('/rest/api/2/field')
.asObject(List)
.body as List<Map>

// Get the story points custom field to use in the script
def storyPointsField = fields.find { it.name == "Story Points" }.id
logger.info("The id of the story points field is: $storyPointsField")

// Note: The search API is limited that to only be able to return a maximum of 50 results
def allStories = get("/rest/api/2/search")
.queryString("jql", "parentEpic =${epicIssueKey} and issuetype = 'Story', 'Bug'")
.queryString("fields", "parent,$storyPointsField")
.asObject(Map)
.body
.issues as List<Map>

logger.info("Total stories for ${epicIssueKey}: ${allStories.size()}")

// Sum the storyPoints
def estimate = allStories.collect { Map story ->
story.fields[storyPointsField] ?: 0

}.sum()
logger.info("Summed Story Points: ${estimate}")

// Store the summed story points on the Story Points field of the epic issue
def summedEstimateField = fields.find { it.name == "Story Points" }.id

logger.info("Custom field ID to update: ${summedEstimateField}")

// Now update the Epic issue
def result = put("/rest/api/2/issue/${epicIssueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
(summedEstimateField): estimate
]
])
.asString()

// check that updating the Epic issue worked
assert result.status >= 200 && result.status < 300

}else{
logger.info("Not an Epic issue so do nothing")
}

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 06, 2019

@Davey

As I suspected, there is a syntax error with your JQL >>>  "parentEpic =${epicIssueKey} and issuetype = 'Story', 'Bug'"

if you replace to anyone of them below may fix your issue

1.  "parentEpic =${epicIssueKey} and (issuetype = 'Story' or issuetype = 'Bug')"

"parentEpic =${epicIssueKey} and issuetype in ('Story', 'Bug')"

 

BR,

Leo

@Leo - You're the bomb.com!   That was it!  

Thanks so much! 

Well now there is a new quirk.   The script is updating the field, but it is giving the max 50 stories and a total of 122 story points to everything.  (faceplam) 

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 06, 2019 • edited

If I'm right scriptrunner goes with search api  internally which is limited in jira(which is not configurable)

you can try with pagination, but I never played with that :( 

Working perfectly now.   

Added a queryString parameter for maxresults = 50 and adjusted the JQL to use the in statement for the issue types! 

 

On to the next project. 

TAGS
AUG Leaders

Atlassian Community Events