How to use enum in ScriptRunner script?

Hi,

I am trying to pass enum to function, but it stil raises errors:

import com.atlassian.jira.component.ComponentAccessor
def plugin = ComponentAccessor.getPluginAccessor().getPlugin('com.almworks.jira.structure')
// Get structure with ID 119
def syncManager = plugin.getModuleDescriptor('sync-manager').getModule()
syncManager.resync(114, SyncDirection.INBOUND, false)

I mean SyncDirection.INBOUND here, API where I found it is available here: http://almworks.com/structure/javadoc/latest/com/almworks/jira/structure/api/sync/SyncDirection.html

It still raises me:

groovy.lang.MissingPropertyException: No such property: SyncDirection for class: Script1
	at Script1.run(Script1.groovy:6)

1 answer

Hm.. Maybe import will resolve the problem?

import com.almworks.jira.structure.api.sync.SyncDirection;

Yes, you will need the import, and @WithPlugin (https://scriptrunner.adaptavist.com/latest/jira/scripting-other-plugins.html#__withplugin) so the classloader can find it. I think it would be better to use @PluginModule (same page) rather than your method.

 

I tried it too, also with @WithPlugin it raises:

unable to resolve class com.almworks.jira.structure.api.sync.SyncDirection

with code:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.sync.SyncDirection
//blah blah blah

also when I use just import com.almworks.jira.structure.

Did you put the right param for WithPlugin? See https://scriptrunner.adaptavist.com/latest/jira/scripting-other-plugins.html#_example. Please paste the full script that doesn't work, the blah blah is the important bit.

That's it:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.sync
import com.almworks.jira.structure.api.sync.SyncDirection
@WithPlugin("com.almworks.jira.structure")

@PluginModule
StructureSyncManager syncManager
syncManager.resync(114, SyncDirection.INBOUND, false)

I'd like to run one direction sync.

It's missing imports, this works for me:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.sync.SyncDirection
import com.almworks.jira.structure.api.sync.StructureSyncManager

@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureSyncManager syncManager

syncManager.resync(114L, SyncDirection.INBOUND, false)

Oh, thanks, that helped! Is it possible to run this code periodically? Every 5 minutes or something?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you