This article shows how to move issues automatically using External scripts library.

This script handles the situation when you move issue from one workflow to another workflow on the source system.

Pre-requisites


Source sideDestination side
projects
ProjectKey_A1
ProjectKey_A2
ProjectKey_B1
ProjectKey_B2
issue types
IssueType_A1
IssueType_A2
IssueType_B1
IssueType_B2
workflows
LocalWorkFlow1
LocalWorkFlow2

Configuration

1. Upload the file with the external script

You need to upload the Move.groovy file into the scripts directory

External scripts library location

Jira Server: $JIRA_HOME/scripts


2. Call the script from the Sync Rules

Once all external .groovy files have been uploaded to the proper directory, you need to call the script from the Sync Rules. 

Every .groovy file includes comments with a detailed explanation on how to use it. Please check the file comments.

Source side

Outgoing sync(data filter)

Add the snippet below to the new line in the end of the data filter

replica.type = issue.type
replica.project = issue.project
replica.status = issue.status

Destination side 

Incoming sync for existing issues(change processor)

Add the snippet below to the new line in the end of the change processor

Move issues automatically according to the specified mapping

The method helps to move issues automatically in case the source issue has been moved to another project or the issue type has been changed on the source side.

Incoming sync for existing issues(change processor)

Move.receive(
	//projectMapping:
	["ProjectKey_A1":"ProjectKey_B1", "ProjectKey_A2":"ProjectKey_B2"],
	//issueTypeMapping:
	["IssueType_A1":"IssueType_B1", "IssueType_A2":"IssueType_B2"],
	//moveStatusMapping:
	["LocalWorkFlow1" : ["LocalWorkFlow2" : ["OPEN": "TO DO"] ] ],
	//sameStatusIfNotInMapping
	true,
	replica, issue
)


Move issue with identical workflows for all issue types

If the workflows are identical for all issue types, you don't need to specify the status mapping.  But you still need to specify project and issue type mappings if the projects and issue types are different.

Move.receive( 
	//projectMapping:
	["ProjectKey_A1":"ProjectKey_B1", "ProjectKey_A2":"ProjectKey_B2"],
	//issueTypeMapping:
	["IssueType_A1":"IssueType_B1", "IssueType_A2":"IssueType_B2"],
	// moveStatusMapping
  	[:], 
  	true, // use the same status if mapping is not specified
 	replica, 
 	issue 
) 


Move issue with different workflows for all issue types

moveStatusMapping - defines, the status of the issue moved to another workflow.

If an issue which is under sync is moved from workflow X to workflow Y and the current status is A, set the status B.

Example: [...,"X":[...,"Y":[...,"A":"B",...],...],...]

Incoming sync for existing issues(change processor)

if (replica.type.name != issue.type.name) {
	Move.move(
 	//moveStatusMapping:
 	["LocalWorkFlow1" : ["LocalWorkFlow2" : ["OPEN": "TO DO"] ] ],
 	//sameStatusIfNotInMapping
	true,
	issue,
	issue.project.key, // the key of the project where the issue is moved to here
	replica.type.name // the name of the issue type where the issue is moved to
	)
}

See also