ScriptRunner Listener condition for specific field update

Julia Foden June 17, 2022

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?

1 answer

1 accepted

1 vote
Answer accepted
Piotr Zadrożny _Eyzee_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 19, 2022

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.

chrome_kpDuWf2j9X.png

 

BTW. you can also accomplish it using Jira Automation. In matter of fact using the same method:

chrome_y1yvlzVXOd.png

 

Best

Piotr

Julia Foden June 20, 2022

Hi @Piotr Zadrożny _Eyzee_ 

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

Piotr Zadrożny _Eyzee_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 20, 2022

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

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