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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


How to automate moving objects in JSM

I'd like to be able to move objects when a certain status is changed. It will only be moving to another object type in the same schema. I don't see this as an option in Automation, so can I use ScriptRunner/Groovy scripting? If so, what command would be used to move an object while retaining history and inbound references? And references from issues in Jira.


Is this possible, or should I look for another route?

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 31, 2023

Yes, you can use scriptrunner to move an object. But it's not a simple command.

You have to re-map all the attributes (even if they are the same), then because moving is an asynchronous process, you might need to wait for it to finish. But you can't wait forever, so you need a timeout.

Here is some sample generic code to move an object in scriptrunner:


import com.adaptavist.hapi.jira.assets.Assets
import com.onresolve.scriptrunner.runner.customisers.PluginModule

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin('com.riadalabs.jira.plugins.insight') insightPlugin

@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
@PluginModule ObjectFacade objectFacade
ObjectBean object = Assets.getByKey('xxx-123') //you'll need to specify the object to move

def TARGET_SCHEMA_ID = 1 //you need to specify the target schema id
def TARGET_OBJECT_TYPE_ID = 1 //you need to specify the target object type id
def MAX_WAIT_MILLIS = 10000 //10 seconds

MoveObjectBean moveObjectBean = new MoveObjectBean()
MoveObjectMapping moveMap = new MoveObjectMapping()
objectTypeAttributeFacade.findObjectTypeAttributeBeans(object.objectTypeId).each { att ->
def attMap = MoveAttributeMapping.create(att, att) "Preparing to move $att (${att.getClass()})", attMap)

moveObjectBean.setIql("Key = $object.objectKey")

def moveSuccess = false

try {
def moveProgress = objectFacade.moveObjects(moveObjectBean)
//wait for move to finish
Integer curWait = 0
log.debug "moveObjectAndWait: Waiting for move to finish: $curWait ($moveProgress.status)"
while (moveProgress.isFinished() == false && curWait < MAX_WAIT_MILLIS) {
curWait = curWait + 100
log.debug "moveObjectAndWait: Waiting for move to finish: $curWait ($moveProgress.status)"
if (moveProgress.isFinished()) { "moveObjectAndWait: Move complete"
return true
} else if (moveProgress.isError()) {
log.error "moveObjectAndWait: error during move - "
} else {
log.warn "moveObjectAndWait: Gave up waiting for move to finish."
} catch (moveEx) {
log.error "moveObjectAndWait: Could not move ${object?.objectKey} to $TARGET_OBJECT_TYPE_ID: $moveEx.message"
return false

I don't know how this works, but thanks! I only needed to take the middle section to use in my script but it does work somehow. Although it doesn't grab any attributes so I needed to update them automatically after moving it.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events