Why would a ScriptRunner listener not fire for all issue types?

Greetings,

I have a conundrum that I need help debugging. Thanks to members of this site, I was able to successfully add a ScriptRunner Listener script that would automatically populate the Organizations field of a Service Desk project upon issue creation. This had been working perfectly for about a week or so. Earlier this week, I noticed that I had issues with no Organization value. 

When I tried to replicate it, I found that only one issue type ("Incident") was not being auto-populated. The script does or listener config has no logic for issue type, so I'm confused by how this could happen. Also, the last 15 event history does not show an item (check mark or error) for any "incident" issue type that's created, but it does for all other issue types. 

Here is the script for my listener (it's set for the events of Issue Created & Issue Moved). Any assistance or feedback is welcome.

import com.atlassian.fugue.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.CustomerOrganization
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.atlassian.servicedesk.api.organization.UsersInOrganizationQuery
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequest
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequestImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.Issue
@Grab(group = 'com.atlassian.servicedesk', module = 'jira-servicedesk-api', version = '3.3.0-REL-0012')
@WithPlugin("com.atlassian.servicedesk")
@PluginModule
ServiceDeskManager serviceDeskManager
@PluginModule
OrganizationService organizationService
def issueManager = ComponentAccessor.getIssueManager()
def issue = event.issue
def currentUser        = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(issue.projectObject)
if (serviceDeskProject.isLeft()) {
    log.error "${serviceDeskProject?.left()?.get()}"
    return
}
//log.error "${serviceDeskProject?.right()?.get()}"
//return
def serviceDeskId      = serviceDeskProject.right()?.get()?.id as Integer
if (! serviceDeskId) {
    log.debug "Could not find service desk id ${serviceDeskId}, maybe the project ${issue.projectObject.key} is not a service desk one."
    return
}
// get the available organizations for that project
def organizationsQuery = new OrganizationsQuery() {
    @Override
    Option<Integer> serviceDeskId() {
        return new Option.Some<Integer>(serviceDeskId)
    }
   @Override
    LimitedPagedRequest pagedRequest() {
        return new LimitedPagedRequestImpl(0, 10, 500)
    }
}
// get the organizations configured for one project and add them
def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery).right().get().results
log.debug "I will add organizations ${organizationsToAdd}"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations")
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), organizationsToAdd), new DefaultIssueChangeHolder())
//issue.setCustomFieldValue(cf, organizationsToAdd)

1 answer

This widget could not be displayed.

Hi Fred, 

You can set logging in order to help you debugging the script.  

Once you done it you will be able to add more log.debug "..." messages and then check your logs for them. And probably you can find the root cause. 

You can ping me when you have more information.

regards, Thanos

Thanos,

I was able to resolve the issue. The issue was that I had a custom event (for another ScriptRunner) function on the Create transition that prevented the listener from executing. Once I straightened out the events in my workflows, the listener is now working as intened. Thanks for the logging tip!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

531 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you