How to retrieve changelogitem using Jira Expressions in ScripRunner Workflow Condition

Jim Litzie April 22, 2021

Hello,

I'm in process of migrating a Jira server instance to Jira cloud and would like to move as many ScriptRunner items as possible.

In the server version, I have a workflow condition using Groovy that checks for a changelog with the field='status' and the toValue='To Business Analyst'.

The changelog is checked only if one of our user picker custom fields (Business Analyst) has a value.

If the Business Analyst contains a value and there's no log record of the issue status being changed to 'To Business Analyst', the workflow condition will return false.

In the Jira Expression, I have the check for the Business Analyst value and a check to see if there are existing changelogs. These seem to work fine:

issue.customfield_10041 != null &&
issue.changelogs.length > 0

 

I can test values in the changelogs as well:

issue.changelogs.filter(c => c.author.displayName == 'Jim').length > 0

 

I am, however, unable to figure out how to get to the ChangelogItem properties. I've attempted several different approaches based on examples on this page

Full disclosure, I don't typically do Web development but have been provided an 'opportunity' by having to convert the scripts.

Any help would be appreciated.

Thanks!

2 answers

1 vote
Jim Litzie April 26, 2021

I was able to finally get something working. It looks a bit strange but seems to work ok so far.

issue.customfield_10041 == null ||
issue.changelogs.filter(c => c.items.filter(i => i.toString == 'To Business Analyst').length > 0).length > 0

0 votes
Kate Kabir
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.
April 25, 2021

Hi @Jim Litzie 

Thank you for your question.

I can confirm that the ScriptRunner for Jira Cloud plugin provides workflow Validators using the Jira Expression Framework as documented in the Atlassian API documentation page located here or in the documentation page located here which explains how to add in a new validator to your workflow.

We can confirm that when viewing the Jira Expression Framework API documentation page linked above you can navigate to the Context variables section which shows what variables are provided by this framework that can be used to create the expression.

If you then click on one of the variables it will show all the properties that can be called on the variable for the expression such as for the issue variable as shown here and you will be able to check this to see if Atlassian provides a variable that contains the item you want to check against.

We can also confirm we have some examples of validators that can be used as a reference guide in the page located here as well as in the documentation page located here.

We would recommend using these documentation pages linked above as a reference guide to help to create the validator expression that you require.

Thank you

Kind Regards

Kate

Suggest an answer

Log in or Sign up to answer