Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,373
Community Members
 
Community Events
165
Community Groups

ScriptRunner Listener condition for specific field update

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 vote

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

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

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
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,098 views 34 44
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you