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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,554,693
Community Members
 
Community Events
184
Community Groups

I want to create a Jira Expression that evaluate if an issue is an incident AND if this issue was moved from one specific queue to another one.

I have this for check Incident: issue.issueType.name == "Incident"

And this to check if the issue was moved:

import groovy.json.JsonSlurper
import java.util.logging.Logger

def issueKey = issue.key
def jsonSlurper = new JsonSlurper()

// variável para checar se a transferencia original
def foundStatusChange = true
logger.info("Status: " + foundStatusChange)

// lê as transferencias ocorridas
def changelog = get("/rest/api/2/issue/${issueKey}?expand=changelog")
.header("Content-Type", "application/json")
.asObject(Map)
.body
.changelog
.histories

changelog.each { entry ->
def author = entry.author.displayName
def created = entry.created
def items = entry.items
items.each { item ->
def fromStatus = item.fromString
def toStatus = item.toString
logger.info("${author} moved this issue from ${fromStatus} to ${toStatus} on ${created}")

// teste de origem da transferencia
if (fromStatus != null && toStatus != null) {
foundStatusChange = false
}
}
}

Does there a way to run this on Jira Expression ?

Thank you.

Clecimar

1 answer

0 votes
Oliver Siebenmarck _Polymetis Apps_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 04, 2023

Hi @Clecimar Fernandes ,

Welcome to the community!

The code you got there looks like Groovy code, that will not work as a Jira Expression. The good news is though, that a Jira Expression will much, much shorter.

So, here it is:

issue.issueType.name == "Incident" && issue.changelogs.filter(c => c.items.filter(f => f.field == "status").length > 0).length > 0

The first part is what you already got, the second part filters the changelog for all entries where the status was updated and then checks if there was at least one.

Hope that helps,
 Oliver

P.S. If you regularly mess around with Jira Expressions, be sure to try our free Expression Tester app and let us know what you think!

Hi Oliver, thank you for your answer! Unfortunately I got this erro message:

2023-05-04 18:39:00.817 ERROR - The condition: issue.issueType.name == "Incident" && issue.changelog.filter(c => c.items.filter(f => f.field == "status").length > 0).length > 0 evaluated to: ["Evaluation failed: \"issue.changelog\" - Unrecognized property of `issue`: \"changelog\" ('changelog'). Available properties of type 'Issue' are:

 And after a lot of customfields...

Do you have some clue about what is happening ?

Clecimar

Oliver Siebenmarck _Polymetis Apps_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 04, 2023

Hi @Clecimar Fernandes ,

In the error message, it says:

issue.changelog

It should be 

issue.changelogs

(Notice the 's' at the end)

It should work with 'changelogs' instead of 'changelog'.

Cheers,
 Oliver

I changed this once I can find changelog at json:

 

"DEV-2121","changelog":{"startAt":0,"maxResults":0,"total":0,"histories":[]},"fields":

 

Also, didn´t find Status.

I´m trying something like this:

issue.issueType.name == "Incident" && (issue.changelog.histories).length > 0

Because I have this:

.body.changelog.histories.items

Does this make sense ?

Thank you.

Clecimar

Oliver Siebenmarck _Polymetis Apps_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 04, 2023

Interestingly, the way an issue is represented within a Jira Expression is different from other representations. For example, getting an issue via the API, it has an 'issuetype' attribute, but within Jira Expressions the same attribute is issueType with a capital T. Changelog vs changelogs is another example.

Where or what for exactly are you using this expression anyway?

Hi Oliver.

I need to check if the issue was moved from one queue to another as in my script and these are the conditions:

In order to run script:

fromSring field must be = null

toString field must be = null

After the first queue change the script shouldn´t run again!

So, is expected the fields be this way:

fromString != null

toString != null

In other words: the script should be run just one time (just one change)

Let me know if it´s clear ?

Thank you for your help.

Clecimar

Hey community, someone else has any idea how to create this Jira Expression ?

Thank you.

Clecimar

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events