I had some troubles to get the changes done in a ScriptRunner listener visible in the issue history. I share in this post my learnings.
Problem description
I wanted to set a custom field in a ScriptRunner listener and have the change documented in the issue history and being able to trigger an email notification (issue updated event).
This is quite a common question (see Solved: Why doesn't Script Listener write to Issue History... and Scriptrunner listener updates not showing in Issue...)
First attempt
My first known approach to set a custom field did not trigger an issue update (it was more like a silent change).
Looking for how to make the issue change visible I have found this solution still based on the issueManager.
I have tried it but couldn't get it to work (no change visible in the issue history).
Second attempt
Then I came to this resource that is based on issueService.
After a test, this works properly i.e. the change is visible in the issue history.
Final solution
Still I needed to change the solution provided in the Script Library.
The structure made it hard to use in my listener script because I was looping on links and had many issues to handle (not only the current one)
I have refactored the original library solution so that the function takes an issue as input argument.
Also one subfunction to get the custom field by name wasn't really needed.
You can see an extract of my final result in this gist:
No comments:
Post a Comment