Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner custom listener script conversion from jira7 to jira6

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 19, 2019

It might sound strange, but in need to convert jira 7 working script to jira 6.

I thought that I made all changes but it still does not work in jira 6.

Could you please take a quick look at two scripts below 1st is for jira 7 that is working fine and 2nd for jira 6 that is not working.

Your hints will be greatly appreciated.

 

But I need to ask you for help. I need to convert script from jira 7 to jira 6. I thought I did all nessesary changes but it is still not working in jira 6.

could you please take a quick look at two scripts below 1st is for jira 7 that is working fine and 2nd for jira 6 but is not working.

 

Thank you for all help

Helen

 

WORKING IN JIRA 7

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.ComponentManager;

import com.atlassian.jira.event.issue.IssueEvent;

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

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.customfields.CustomFieldType;

import com.atlassian.jira.issue.fields.CustomField;

import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl;

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

import com.atlassian.jira.issue.Issue;

import com.atlassian.jira.issue.link.IssueLink;

import com.atlassian.jira.issue.link.IssueLinkManager;

import com.atlassian.jira.issue.ModifiedValue;

import com.atlassian.jira.issue.MutableIssue;

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

import com.atlassian.jira.project.version.VersionManager;

import com.atlassian.jira.util.ImportUtils;

import org.apache.log4j.Category;

 

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def epicissue = event.issue as MutableIssue

def issueManager = ComponentAccessor.getIssueManager();

def versionManager = ComponentAccessor.getVersionManager();

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

 

if (epicissue.getIssueType().getName() == "Epic")

    issueLinkManager.getOutwardLinks(epicissue.id).each { issueLink ->      

             if (issueLink.issueLinkType.name == "Epic-Story Link"  && 

          issueLink.getDestinationObject().getIssueType().name == "Story"

         )

       {

MutableIssue issue = issueLink.getDestinationObject() as MutableIssue;

def currentValue = epicissue.getFixVersions()

issue.setFixVersions(currentValue);

issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

 

               

boolean wasIndexing = ImportUtils.isIndexIssues();

IssueIndexingService indexing = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)

indexing.reIndex(issue)

ImportUtils.setIndexIssues(wasIndexing)

        }

  }

 

NOT WORKING IN JIRA 6

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

 

import com.atlassian.jira.ComponentManager;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.issue.customfields.CustomFieldType;

import com.atlassian.jira.issue.fields.CustomField;

import org.apache.log4j.Category;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.ModifiedValue;

import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl;

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

import com.atlassian.jira.util.ImportUtils;

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

import com.atlassian.jira.issue.link.IssueLink;

import com.atlassian.jira.issue.link.IssueLinkManager;

import com.atlassian.jira.issue.Issue;

import com.atlassian.jira.issue.link.IssueLink;

import com.atlassian.jira.event.issue.IssueEvent;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.MutableIssue;

 

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def epicissue = event.issue as MutableIssue

def issueManager = ComponentAccessor.getIssueManager();

def user = authContext.getLoggedInUser()

if (epicissue.IssueType.name == "Epic")

    issueLinkManager.getOutwardLinks(epicissue.getId()).each { issueLink ->      

 if (issueLink.issueLinkType.name == "Epic-Story Link"  && 

          issueLink.getDestinationObject().getIssueType().name == "Story"

         )

       {

   MutableIssue issue = issueLink.getDestinationObject() as MutableIssue;         

 def currentValue = epicissue.getFixVersions()

issue.setFixVersions(currentValue);

           issueManager.updateIssue(event.getUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)

//issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

 

 

        }

  }

 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
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 25, 2019

This script to sync fixVersions from Epic to Story works in Jira 6.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItemImpl;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.project.version.Version;
import com.atlassian.jira.project.version.VersionManager;
import com.atlassian.jira.util.ImportUtils;
import com.opensymphony.workflow.InvalidInputException;
import org.apache.log4j.Category;


def issueManager = ComponentAccessor.getIssueManager();
def versionManager = ComponentAccessor.getVersionManager();
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

def epicissue = event.getIssue();


if (epicissue.issueType.name == "Epic")

issueLinkManager.getOutwardLinks(epicissue.id).each { issueLink ->

if (issueLink.issueLinkType.name == "Epic-Story Link" &&
issueLink.getDestinationObject().getIssueType().name == "Story"
)
{

MutableIssue issue = issueLink.getDestinationObject() as MutableIssue;


def currentValue = epicissue.getAffectedVersions()


issue.setAffectedVersions(currentValue);

issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

}
}

TAGS
AUG Leaders

Atlassian Community Events