JIRA EXPRESSION

Clecimar Fernandes May 4, 2023

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_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 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!

Clecimar Fernandes May 4, 2023

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_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 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

Clecimar Fernandes May 4, 2023

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_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 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?

Clecimar Fernandes May 6, 2023

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

Clecimar Fernandes May 8, 2023

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