How to get listener to only 'fire once'

Chris Thompson September 4, 2017

Hi Everyone,

I have created a listner using the ScriptRunner clone issues and links listner template. It is to create linked issues in different projects dependant on tick boxes in a multi tick list selectd during a transition.

The 'Event' it is set to is 'issue updated' and condition is

'Investment Report' in cfValues['RM Post Meeting Work Required Checkbox']*.value

Which does the job, but the probelm I have is that it is firing every time the issue is updated creating multiple linked issues. How can I tell the listner not to duplicate if the linked issue already exists. I have tried narrowing the Event from issue updated to custom field updated or custome field entered, but this doesnt create the linked issue.

Thanks very much.

1 answer

1 vote
MoroSystems Support
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.
September 4, 2017

It could be enough to extend the condition, right? I would use something like this:

issueLinkManager.getInwardLinks(issue.getId()).isEmpty() && issueLinkManager.getOutwardLinks(issue.getId()).isEmpty()
Chris Thompson September 4, 2017

thankyou very much that appears to have worked perfectly... I have been banging my head against a wall trying to get that to work. Thanks so much

Chris Thompson September 5, 2017

Ahh, I thought I had it but im not quite there on further testing.. its possible that one issue could have multiple linked issues if more than one option is selected in the check box - so just verifying that there are no issues there isnt quite enough. I just cant the last tweak right. I need it to look at the tick box to see if the option has been selected, and if it has to look at the existing linked issues to see if there is already an issue that contains the option name in the summary. But that it will still allow parrallel listners to create issues if other options are selected in the checkbox.

I have tried to alter slightly to:

'Document 1' in cfValues['Multi Choice CheckBox']*.value
AndAlso issueLinkManager.getInwardLinks(issue.getId()).Notcontain'Document1' && issueLinkManager.getOutwardLinks(issue.getId()).Notcontain'Document1' 
MoroSystems Support
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.
September 5, 2017

Methods getInwardLinks and getOutwardLinks return IssueLink object. You can bet destination or source issue using issuelink.getDestinationObject() or issuelink.getSourceObject(). Then getSummary() method will give you summary value for comparison.

But I'm not sure if it will be easy to use these methods in the condition because you need to use some foreach cycle in it...

Chris Thompson September 5, 2017

thanks v much, just giving that a go. You are right.. it is tricky

MoroSystems Support
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.
September 5, 2017

You can always implement script on issue transition but it is little complicated...you'd have to implement issue creation, issues linking etc...

Chris Thompson September 5, 2017

Thanks, I think that is a bit complex for me at this stage. Still getting around the basics of writing script. I have spent most of the morning trying to get the getSourceObject alternative to work. I am resolved to just inserting aprompt for the users to create a new issue if a certain custom field is selected and rely on it being done manually. 

Appreceate your help.

Suggest an answer

Log in or Sign up to answer