I don’t have the exact script in hand but I wanted to make you aware that from the scripts, you have access to all the Jira Java APIs that allow you to do this kind of actions. If you are familiar with script runner then you will have some experience with writing this kind of scripts. For example to get the IssueService service from the script, you can do something like:
def is = com.atlassian.jira.component.ComponentAccessor.getIssueService()