You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey community, someone else has any idea how to create this Jira Expression ?
Thank you.
Clecimar
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.