Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Stop Repeating Automated Steps after Update Event

Paul Martin August 3, 2022

I have setup a simple listener to create an issue when a field is selected in JIRA during an update event. The problem is, when a further change is made to the same ticket (which generates another update event) the listener picks this up and creates another issue (providing the condition is still true)

How can I amend the listener to create an issue only when the specific action is done, and nothing else. 

Condition: 

'SpecificValue' in cfValues['SpecificCF']*.value

 

Thanks all. 


Steps to recreate:

  1. Create issue 1234
  2. Update custom field (SpecificCF) in issue 1234 to SpecificValue
    1. This will now create a new issue 1235
  3. Update the description of issue 1234
    1. A new issue has been created 1236

 

2 answers

1 accepted

2 votes
Answer accepted
Radek Dostál
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.
August 3, 2022

I think what you need is to remove the condition and move it into the script code itself, because the condition will always be true, no matter what, with each issue update.

 

Taking https://community.atlassian.com/t5/Adaptavist-questions/Listener-Condition-for-CustomField-change-AND-custom-date-field/qaq-p/1009955 as inspiration, the steps would be:

 - issue get updated, thus this fires IssueUpdated event

 - the issue itself is "already updated" when the 'issue' variable enters the script code, hence you need to find if it was the CustomField value itself that was changed - by looking into what was changed which is part of the event

 - inside the code, see if CustomField was changed as part of this update, if so, then you do what you need to do, otherwise, we can safely assume the field was not changed, thus we don't care

 

So to do that, you use the event to find what was changed

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "SpecificCF name"}

 

If there was a change, you can now find what the new value is:

def newString = change?.get("newstring")

 

And if it was just set on the issue

if (newString != null && newString.equals("SpecificValue")

 

Then it should be safe to assume you're good to do the other steps.

 

I don't have IDE in front of me right now so I hope the code snippets are correct, if not I can take a look tomorrow and fix them.

This also depends how your listener is implemented currently and if you are able to fit these in.

 

In any case - need to use the event to find if the custom field was actually changed, as condition will always be true in this context.

Paul Martin August 4, 2022

Thanks for your help and breaking this down for me @Radek Dostál

This worked perfectly. 

0 votes
Aditya Sastry
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.
August 3, 2022

A simple hack would be to populate a custom field (maybe named as flag) to some value in the original issue after the new issue is created. Don't need to add this field to the issue screens but use it to evaluate if the listener needs to process new issue creation. If the custom field is empty proceed with issue creation else exit.

Let me know if you need more information.

Please mark it as answered if it solves your problem.

Thanks,
Aditya

Suggest an answer

Log in or Sign up to answer