Script Runner, life saver! (or how I replaced Outlook by JIRA)


Posted by
Anand UNADKAT

June 10, 2014

If you need to configure  JIRA to meet your organisation requirements and have a developer background, Script Runner can save your life. In this article, I’ll tell you how it saved mine when setting up JIRA for users.

Users always have a list of requirements for which they would like JIRA to behave or be configured. However, by default, JIRA does not always allow you to do it without the help of some add-ons.

Use scripting to make JIRA the way you want it

In the Atlassian Marketplace, you can find many add-ons which will allow you to configure JIRA to meet these requirements but this, quite often, comes with a price tag. However, the amazing creation by Jamie Echlin called Script Runner comes to the rescue almost all the time. Reason being, you can do almost anything by writing a script.

So for people reading this blog, who don’t know what Script Runner is, it is an add-on which uses groovy scripting language for adding complex configuration to your JIRA instance. Script Runner already has built-in scripts that will help with workflow post-functions, validators and conditions, however you can also use it for JQL queries as well as listeners and scripted fields to give you a starting base. For example, searching issues with attachments.

How I replaced Outlook by JIRA

Going back to my experience, users wanted to replace Outlook by JIRA. They use Outlook for any ad-hoc tasks that come in as emails and they reply back and forth to complete the task. So being an admin, there is nothing stopping me from telling them to use JIRA, however not bearing in mind how complex the system is actually going to be.

Users requirements

Their Outlook had email rules which according to the subject and the sender, sent emails to a particular folder. This had to be implemented into JIRA. So their folders are basically ‘Type of Requests’ and this was created as a custom field within JIRA and with the help of JETI (JIRA Email This Issue) add-on, it can generate custom fields with emails for users to identify the sender of an issue. We all know there this is a workflow post function which copies a field value from one field to another using JIRA Suites Utilities add-on

However, updating a custom field with a value depending on a particular value from another custom field is what JIRA does not offer, even with the help of JIRA Suites Utilities, there is no way that this could have been done, so this is where Script Runner came in useful. One, it was a free add-on which is always a plus for any admin/users, and two, it was going to meet users requirements hence a life saver.

The solution I implemented

This script basically looked at an issue during its creation, and according to the sender and the subject of the email, it would populate the Type of Request, Priority, Component, Assignee and set the SLA. One thing that they also wanted was to fast-track an issue which has not met the rules and complete the issue by setting its Resolution and a listener which would listen to Issue Updated event and according to that set another custom field within an issue. All of this was done by using one add-on. Sample script can be found below

//Type of Request field
optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class)
cf2 = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find{it.name =='Type of Request'}

//Business Unit Owner Field
optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class)
cf3 = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find{it.name =='Business Unit'}

//Sender Field
cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sender")
val = issue.getCustomFieldValue(cf)

if(issue.getSummary.toLowerCase().contains("sample text")) {
    Project project = issue.getProjectObject()
    ProjectComponent component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(), "name of component")
    issue.setComponentObjects([component])

    def fieldConfig = cf2.getRelevantConfig(issue)
    def option = optionsManager.getOptions(fieldConfig).find {it.value == "name of type of request"}
    issue.setCustomFieldValue(cf2, option)

    def fieldConfig1 = cf3.getRelevantConfig(issue)
    def option1 = optionsManager.getOptions(fieldConfig1).find {it.value == "name of business unit"}
    issue.setCustomFieldValue(cf3, option1)

    issue.setPriorityId("priorityID")
} else {
return false
}
Sample Groovy Script

It’s all good me praising this add-on, however it does come with its drawbacks. One of the major drawback is, you have to come from a developer background and understand Groovy to write complex scripts. Which can mean that it can be show stopper and divert you to paid add-ons which is not always positive with many users. However there are a lot of online materials which can help any admin coming from all the backgrounds to start from the basics of scripting.

Your turn to be a JIRA hero

Now you know, whatever the requirements, there is one add-on which will be able to do it, however you will need to be able to write Groovy scripts to make it work, which with the help of online material, can be achieved.