ScriptRunner Custom Listener Sync affectedVersion help adding condition

helen levich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2019

Jira 7/ScriptRunner Listener syncs affectedVersion from parent story to sub-tasks.


There is one condition that needed to be added which is:

if child sub-task=bug and   affectedVersion on bug not equal Value1 or Value2 then don't sync value of affected version from parent story to sub-task

 

------------------------------

This is original script that syncs affectedVersion for all sub-tasks from parent story:

import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.ImportUtils

def issueManager = ComponentAccessor.issueManager
def indexingService = ComponentAccessor.getComponent(IssueIndexingService.class)

def fixIssue = event.issue

if(fixIssue.issueType.name == "Story"){
def changeItems = event.changeLog?.getRelated("ChildChangeItem")
if(fixIssue.affectedVersions?.name && changeItems.any{it.field == 'Version'}){
fixIssue.subTaskObjects.each { subTask ->
subTask.affectedVersions = fixIssue.affectedVersions
issueManager.updateIssue(event.user, subTask, EventDispatchOption.ISSUE_UPDATED, false)
//Put JIRA in indexing mode
def wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
//update the JIRA index
indexingService.reIndex(subTask)
ImportUtils.setIndexIssues(wasIndexing);
}
}
}

 

I'm trying to add condition but need help, but it does not work. 

import com.atlassian.jira.issue.index.IssueIndexingService

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.util.ImportUtils

 

def issueManager = ComponentAccessor.issueManager

def indexingService = ComponentAccessor.getComponent(IssueIndexingService.class)

 

def fixIssue = event.issue

 

if(fixIssue.issueType.name == "Story"){

   def changeItems = event.changeLog?.getRelated("ChildChangeItem")

   if(fixIssue.affectedVersions?.name && changeItems.any{it.field == 'Version'}){

      fixIssue.subTaskObjects.each { subTask ->

 

          subTask.affectedVersions = fixIssue.affectedVersions

         

subTasks.each {

    if (subTasks.issueTypeObject.name == "Bug" && (subTask.affectedVersions != "Value1") && (subTask.affectedVersions != "Value2")) {

        return null

    }

 

    else    

 

 

         issueManager.updateIssue(event.user, subTask,  EventDispatchOption.ISSUE_UPDATED, false)

    }

         //Put JIRA in indexing mode

         def wasIndexing = ImportUtils.isIndexIssues();

         ImportUtils.setIndexIssues(true);

         //update the JIRA index

         indexingService.reIndex(subTask)

         ImportUtils.setIndexIssues(wasIndexing);

      }

   }

}

1 answer

1 accepted

0 votes
Answer accepted
helen levich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2019

import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.ImportUtils

def issueManager = ComponentAccessor.issueManager
def indexingService = ComponentAccessor.getComponent(IssueIndexingService.class)

def fixIssue = event.issue

if(fixIssue.issueType.name == "Story"){
def changeItems = event.changeLog?.getRelated("ChildChangeItem")
if(fixIssue.affectedVersions?.name && changeItems.any{it.field == 'Version'}){
fixIssue.subTaskObjects.each { subTask ->

if (subTask.issueType.name == "Bug" && (subTask.affectedVersions.find {it.name != "Value1"}) && (subTask.affectedVersions.find {it.name != "Value2"}) ) {
return null
}
else
{

subTask.affectedVersions = fixIssue.affectedVersions
issueManager.updateIssue(event.user, subTask, EventDispatchOption.ISSUE_UPDATED, false)

}

//Put JIRA in indexing mode
def wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
//update the JIRA index
indexingService.reIndex(subTask)
ImportUtils.setIndexIssues(wasIndexing);
}
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events