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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner custom listener script conversion from jira7 to jira6

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

0 votes
Answer accepted

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)

}
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

568 views 15 18
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you