Hi
I have started trialling ScriptRunner to see can it overcome some of Automation's limitations (I love Automation but it does have limitations)
I am trying to create a script listener that will execute on the Issue Updated event only on condition that the update is on a specific field, in my case Fix Versions.
Can someone advise how to write this condition please?
Hi @Julia Foden ,
You can create Listener, set event to Issue Updated, leave condition empty (it evaluates jira expression which can be not sufficient here), and write the following in Code section:
def fixVersionChanged = changelog?.items.find { it['field'] == 'Fix Version' }
if (!fixVersionChanged) {
logger.info("fixVersion was not modified")
return;
}
logger.info("fixVErsion was modified")
The script checks the changlog to find out which issue element has been updated. This changlog can look somehing like this:
[
id:10130,
items: [
[
field:Fix Version,
fieldtype:jira,
fieldId:fixVersions,
from:null,
fromString:null,
to:10000,
toString:v1
]
]
]
So you can use also fromString and toString to determine what version has been added or removed.
BTW. you can also accomplish it using Jira Automation. In matter of fact using the same method:
Best
Piotr
Thank you, I'll try this later.
I know I can do it with automation, and the 'Field Value Changed' trigger is available there also. The reason I want to try ScriptRunner is because of what comes later - I want to loop rather than have multiple branches executing at the same time. I'll have a go with ScriptRunner and might come back with further questions :)
Why is it better to leave the condition empty? Are there any circumstances where it is appropriate to use a condition?
Thanks,
Julia
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Of course, I forgot about the most common one "Field Value Changed" :)
Regarding script conditions, in Jira Cloud as far as I believe, you need to provide Jira expression: https://developer.atlassian.com/cloud/jira/platform/jira-expressions which has limited capabilities and is much harder to work with than regular groovy statements. You can nevertheless use it. In your case it would be:
issue.changelogs[0].items.filter(changeLogItem => changeLogItem.field == 'Fix Version').length > 0
and then of course in the Code section your main script.
To find more info about Jira expression structure check this doc: https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference
Piotr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.