Forums

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

Script Runner listener slow down Jira UI?

Tomasz Bryła
Contributor
December 3, 2018

Hi,

In last week I add listener to my Jira. The listener is run when issue is update and if value of custom field named Email Users  is changed then i search by API users in CRM for Jira addon. Unfortunately, since launching this feature, users report me a slower Jiry activity, even if this field is not edited and only performs a workflow transition, or change the assigned person. Can anyone have a look at my script and help me optimize it?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import groovy.json.JsonSlurper

def userManager = ComponentAccessor.getUserManager()


def issue = event.getIssue()
def key = issue.getKey().toString()
def assignee = userManager.getUserByKey("reporter")
def cfm = ComponentAccessor.getCustomFieldManager()
def email = cfm.getCustomFieldObjectByName("Email Users")
def crmContacts = cfm.getCustomFieldObjectByName("CRM Contacts")
def commentManager = ComponentAccessor.commentManager
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Email Users"}
String idContacts
if (change)
{
String emailVal = issue.getCustomFieldValue(email).toString()
String[] mail
mail = emailVal.split(', ')
for (String val : mail){

def curl = "E:/curl/bin/curl.exe -u user:password https://jira.mydomain.com/plugins/servlet/crm/api?command=searchEntities&crm_param_1=contact_email&crm_param_1_value=${val}&tableName=CONTACTS&userName=usernam&apiKey=key"

def output = curl.execute().text
def slurper = new groovy.json.JsonSlurper()
def results = slurper.parseText(output)



if (results.count == 1)
{
def id = results.records.id.toString()
def idContact = id.substring(1, id.length() - 1)
idContacts = idContacts + ",${idContact}"

}
else if (results.count == 0 )
{
def curl2 = "E:/curl/bin/curl.exe -u user:password https://jira.mydomain.com/plugins/servlet/crm/api?command=searchEntities&crm_param_1=contacts_field_06c937c1-4767-40c4-8861-71d4510ebcfc&crm_param_1_value=${val}&tableName=CONTACTS&userName=usernam&apiKey=key"
def output2 = curl2.execute().text
def slurper2 = new groovy.json.JsonSlurper()
def results2 = slurper2.parseText(output2)
if (results2.count == 1)
{
def id2 = results2.records.id.toString()
def idContact2 = id2.substring(1, id2.length() - 1)
idContacts = idContacts + ",${idContact2}"
}
else if (results2.count == 0)
{
def curl3 = "E:/curl/bin/curl.exe -u user:password https://jira.mydomain.com/plugins/servlet/crm/api?command=searchEntities&crm_param_1=contacts_field_01b3ff4a-f188-4dda-9ad0-b777c2832427&crm_param_1_value=${val}&tableName=CONTACTS&userName=usernam&apiKey=key"
def output3 = curl3.execute().text
def slurper3 = new groovy.json.JsonSlurper()
def results3 = slurper3.parseText(output3)
if (results3.count == 1)
{
def id3 = results3.records.id.toString()
def idContact3 = id3.substring(1, id3.length() - 1)
idContacts = idContacts + ",${idContact3}"
}
}
}

}
def changeHolder = new DefaultIssueChangeHolder();
crmContacts.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(crmContacts), idContacts), changeHolder);
issue.store()
}

 

0 answers

Suggest an answer

Log in or Sign up to answer